mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:40:38 +00:00
[NewGVN] Fix handling of assumes
This patch fixes two bugs: * test1: Previously assume(a >= 5) concluded that a == 5. That's only valid for assume(a == 5)... * test2: If operands were swapped, additional users were added to the wrong cmp operand. This resulted in an "unsettled iteration" assertion failure. Patch by Nikita Popov Differential Revision: https://reviews.llvm.org/D46974 llvm-svn: 333007
This commit is contained in:
parent
44192f816f
commit
2b00b41048
@ -1585,11 +1585,11 @@ NewGVN::performSymbolicPredicateInfoEvaluation(Instruction *I) const {
|
||||
SwappedOps ? Cmp->getSwappedPredicate() : Cmp->getPredicate();
|
||||
|
||||
if (isa<PredicateAssume>(PI)) {
|
||||
// If the comparison is true when the operands are equal, then we know the
|
||||
// operands are equal, because assumes must always be true.
|
||||
if (CmpInst::isTrueWhenEqual(Predicate)) {
|
||||
// If we assume the operands are equal, then they are equal.
|
||||
if (Predicate == CmpInst::ICMP_EQ) {
|
||||
addPredicateUsers(PI, I);
|
||||
addAdditionalUsers(Cmp->getOperand(0), I);
|
||||
addAdditionalUsers(SwappedOps ? Cmp->getOperand(1) : Cmp->getOperand(0),
|
||||
I);
|
||||
return createVariableOrConstant(FirstOp);
|
||||
}
|
||||
}
|
||||
|
26
test/Transforms/NewGVN/assumes.ll
Normal file
26
test/Transforms/NewGVN/assumes.ll
Normal file
@ -0,0 +1,26 @@
|
||||
; RUN: opt < %s -newgvn -S | FileCheck %s
|
||||
|
||||
; CHECK-LABEL: @test1
|
||||
; CHECK: ret i32 %arg
|
||||
define i32 @test1(i32 %arg) {
|
||||
%cmp = icmp sge i32 %arg, 5
|
||||
call void @llvm.assume(i1 %cmp)
|
||||
ret i32 %arg
|
||||
}
|
||||
|
||||
; CHECK-LABEL: @test2
|
||||
; CHECK: ret i32 %arg
|
||||
define i32 @test2(i32 %arg, i1 %b) {
|
||||
br label %bb
|
||||
|
||||
bb:
|
||||
%a = phi i32 [ 1, %0 ], [ 2, %bb ]
|
||||
%cmp = icmp eq i32 %arg, %a
|
||||
call void @llvm.assume(i1 %cmp)
|
||||
br i1 %b, label %bb, label %end
|
||||
|
||||
end:
|
||||
ret i32 %arg
|
||||
}
|
||||
|
||||
declare void @llvm.assume(i1 %cond)
|
Loading…
Reference in New Issue
Block a user