[llvm-commits] [llvm] r134177 - in /llvm/trunk: lib/Transforms/Scalar/IndVarSimplify.cpp test/Transforms/IndVarSimplify/no-iv-rewrite.ll
Andrew Trick
atrick at apple.com
Thu Jun 30 12:02:17 PDT 2011
Author: atrick
Date: Thu Jun 30 14:02:17 2011
New Revision: 134177
URL: http://llvm.org/viewvc/llvm-project?rev=134177&view=rev
Log:
indvars -disable-iv-rewrite: handle cloning binary operators that cannot overflow.
Modified:
llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
llvm/trunk/test/Transforms/IndVarSimplify/no-iv-rewrite.ll
Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=134177&r1=134176&r2=134177&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Thu Jun 30 14:02:17 2011
@@ -659,9 +659,11 @@
LHS, RHS,
NarrowBO->getName());
Builder.Insert(WideBO);
- if (NarrowBO->hasNoUnsignedWrap()) WideBO->setHasNoUnsignedWrap();
- if (NarrowBO->hasNoSignedWrap()) WideBO->setHasNoSignedWrap();
-
+ if (const OverflowingBinaryOperator *OBO =
+ dyn_cast<OverflowingBinaryOperator>(NarrowBO)) {
+ if (OBO->hasNoUnsignedWrap()) WideBO->setHasNoUnsignedWrap();
+ if (OBO->hasNoSignedWrap()) WideBO->setHasNoSignedWrap();
+ }
return WideBO;
}
llvm_unreachable(0);
@@ -1121,6 +1123,8 @@
while (!SimpleIVUsers.empty()) {
Instruction *UseInst, *Operand;
tie(UseInst, Operand) = SimpleIVUsers.pop_back_val();
+ // Bypass back edges to avoid extra work.
+ if (UseInst == CurrIV) continue;
if (EliminateIVUser(UseInst, Operand)) {
pushIVUsers(Operand, Simplified, SimpleIVUsers);
Modified: llvm/trunk/test/Transforms/IndVarSimplify/no-iv-rewrite.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/no-iv-rewrite.ll?rev=134177&r1=134176&r2=134177&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/no-iv-rewrite.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/no-iv-rewrite.ll Thu Jun 30 14:02:17 2011
@@ -160,6 +160,8 @@
entry:
br label %loop
+; Test inserting a truncate at a phi use.
+;
; CHECK: loop:
; CHECK: phi i64
; CHECK: trunc
@@ -189,14 +191,17 @@
ret void
}
-; CHECK: loop:
-; CHECK: phi i32
-; CHECK-NOT: phi
-; CHECK: exit:
define void @identityphi(i32 %limit) nounwind {
entry:
br label %loop
+; Test an edge case of removing an identity phi that directly feeds
+; back to the loop iv.
+;
+; CHECK: loop:
+; CHECK: phi i32
+; CHECK-NOT: phi
+; CHECK: exit:
loop:
%iv = phi i32 [ 0, %entry], [ %iv.next, %control ]
br i1 undef, label %if.then, label %control
@@ -212,3 +217,32 @@
exit:
ret void
}
+
+define i64 @cloneOr(i32 %limit, i64* %base) nounwind {
+entry:
+ ; ensure that the loop can't overflow
+ %halfLim = ashr i32 %limit, 2
+ br label %loop
+
+; Test cloning an or, which is not an OverflowBinaryOperator.
+;
+; CHECK: loop:
+; CHECK: phi i64
+; CHECK-NOT: sext
+; CHECK: or i64
+; CHECK: exit:
+loop:
+ %iv = phi i32 [ 0, %entry], [ %iv.next, %loop ]
+ %t1 = sext i32 %iv to i64
+ %adr = getelementptr i64* %base, i64 %t1
+ %val = load i64* %adr
+ %t2 = or i32 %iv, 1
+ %t3 = sext i32 %t2 to i64
+ %iv.next = add i32 %iv, 2
+ %cmp = icmp slt i32 %iv.next, %halfLim
+ br i1 %cmp, label %loop, label %exit
+
+exit:
+ %result = and i64 %val, %t3
+ ret i64 %result
+}
More information about the llvm-commits
mailing list