diff options
author | Jingyue Wu <jingyue@google.com> | 2015-05-13 18:12:24 +0000 |
---|---|---|
committer | Jingyue Wu <jingyue@google.com> | 2015-05-13 18:12:24 +0000 |
commit | c74e33bffe89b8b85da45640b41418d2850f394d (patch) | |
tree | d39722abb8643d38a7e252cae0ef758273cafaac /llvm/lib/Transforms | |
parent | d43f0c5e82f9df971a32d46d529dca563674dfcc (diff) | |
download | bcm5719-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
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/NaryReassociate.cpp | 12 |
1 files changed, 8 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; } |