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 | 7f0170c1975fe55c58f6f2a968e1fc2248732fbe (patch) | |
tree | fcc1c35b5f5d331f33390c9a2cc2fc8bc2b850ee /lib/Transforms/InstCombine | |
parent | daf27ea899fbd94a020cc6f4680279ea0ac65064 (diff) | |
download | llvm-7f0170c1975fe55c58f6f2a968e1fc2248732fbe.tar.gz llvm-7f0170c1975fe55c58f6f2a968e1fc2248732fbe.tar.bz2 llvm-7f0170c1975fe55c58f6f2a968e1fc2248732fbe.tar.xz |
Don't attempt to add 'nsw' when intermediate instructions had no such guarantee.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@137572 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine')
-rw-r--r-- | lib/Transforms/InstCombine/InstructionCombining.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index 85091afaf2..4166636114 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/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(); } |