summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJingyue Wu <jingyue@google.com>2015-05-13 18:12:24 +0000
committerJingyue Wu <jingyue@google.com>2015-05-13 18:12:24 +0000
commitc74e33bffe89b8b85da45640b41418d2850f394d (patch)
treed39722abb8643d38a7e252cae0ef758273cafaac
parentd43f0c5e82f9df971a32d46d529dca563674dfcc (diff)
downloadbcm5719-llvm-c74e33bffe89b8b85da45640b41418d2850f394d.tar.gz
bcm5719-llvm-c74e33bffe89b8b85da45640b41418d2850f394d.zip
[NaryReassociate] avoid running forever
Avoid running forever by checking we are not reassociating an expression into the same form. Tested with @avoid_infinite_loops in nary-add.ll llvm-svn: 237269
-rw-r--r--llvm/lib/Transforms/Scalar/NaryReassociate.cpp12
-rw-r--r--llvm/test/Transforms/NaryReassociate/nary-add.ll11
2 files changed, 19 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/NaryReassociate.cpp b/llvm/lib/Transforms/Scalar/NaryReassociate.cpp
index 7d3080dcd9b..af61068c97b 100644
--- a/llvm/lib/Transforms/Scalar/NaryReassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/NaryReassociate.cpp
@@ -217,10 +217,14 @@ Instruction *NaryReassociate::tryReassociateAdd(Value *LHS, Value *RHS,
// = (A + RHS) + B or (B + RHS) + A
const SCEV *AExpr = SE->getSCEV(A), *BExpr = SE->getSCEV(B);
const SCEV *RHSExpr = SE->getSCEV(RHS);
- if (auto *NewI = tryReassociatedAdd(SE->getAddExpr(AExpr, RHSExpr), B, I))
- return NewI;
- if (auto *NewI = tryReassociatedAdd(SE->getAddExpr(BExpr, RHSExpr), A, I))
- return NewI;
+ if (BExpr != RHSExpr) {
+ if (auto *NewI = tryReassociatedAdd(SE->getAddExpr(AExpr, RHSExpr), B, I))
+ return NewI;
+ }
+ if (AExpr != RHSExpr) {
+ if (auto *NewI = tryReassociatedAdd(SE->getAddExpr(BExpr, RHSExpr), A, I))
+ return NewI;
+ }
}
return nullptr;
}
diff --git a/llvm/test/Transforms/NaryReassociate/nary-add.ll b/llvm/test/Transforms/NaryReassociate/nary-add.ll
index 39d7c59ef9d..b3093ff6ecd 100644
--- a/llvm/test/Transforms/NaryReassociate/nary-add.ll
+++ b/llvm/test/Transforms/NaryReassociate/nary-add.ll
@@ -196,3 +196,14 @@ define void @iterative(i32 %a, i32 %b, i32 %c) {
ret void
}
+
+define void @avoid_infinite_loop(i32 %a, i32 %b) {
+; CHECK-LABEL: @avoid_infinite_loop
+ %ab = add i32 %a, %b
+; CHECK-NEXT: %ab
+ %ab2 = add i32 %ab, %b
+; CHECK-NEXT: %ab2
+ call void @foo(i32 %ab2)
+; CHECK-NEXT: @foo(i32 %ab2)
+ ret void
+}
OpenPOWER on IntegriCloud