diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2011-08-14 03:41:33 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2011-08-14 03:41:33 +0000 |
commit | ae13df60a69d93374c39c3457ba4b493da2ffc65 (patch) | |
tree | 9b32df2937719376924ea14971b54c20a92cad71 /llvm/lib/Transforms | |
parent | de49278c2655bd5a52f1d8b6b23c737e56fcc3a1 (diff) | |
download | bcm5719-llvm-ae13df60a69d93374c39c3457ba4b493da2ffc65.tar.gz bcm5719-llvm-ae13df60a69d93374c39c3457ba4b493da2ffc65.zip |
Don't attempt to add 'nsw' when intermediate instructions had no such guarantee.
llvm-svn: 137572
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 85091afaf26..41666361141 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -146,7 +146,6 @@ static bool MaintainNoSignedWrap(BinaryOperator &I, Value *B, Value *C) { return !Overflow; } - /// SimplifyAssociativeOrCommutative - This performs a few simplifications for /// operators which are associative or commutative: // @@ -197,7 +196,10 @@ bool InstCombiner::SimplifyAssociativeOrCommutative(BinaryOperator &I) { I.setOperand(1, V); // Conservatively clear the optional flags, since they may not be // preserved by the reassociation. - if (MaintainNoSignedWrap(I, B, C)) { + if (MaintainNoSignedWrap(I, B, C) && + (!Op0 || (isa<BinaryOperator>(Op0) && Op0->hasNoSignedWrap()))) { + // Note: this is only valid because SimplifyBinOp doesn't look at + // the operands to Op0. I.clearSubclassOptionalData(); I.setHasNoSignedWrap(true); } else { @@ -292,10 +294,11 @@ bool InstCombiner::SimplifyAssociativeOrCommutative(BinaryOperator &I) { I.setOperand(1, Folded); // Conservatively clear the optional flags, since they may not be // preserved by the reassociation. - if (MaintainNoSignedWrap(I, C1, C2)) { + if (MaintainNoSignedWrap(I, C1, C2) && Op0->hasNoSignedWrap() && + Op1->hasNoSignedWrap()) { + New->setHasNoSignedWrap(true); I.clearSubclassOptionalData(); I.setHasNoSignedWrap(true); - New->setHasNoSignedWrap(true); } else { I.clearSubclassOptionalData(); } |