diff options
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index cd391d0385e..0695ec17e36 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -83,11 +83,18 @@ bool InstCombiner::SimplifyDemandedInstructionBits(Instruction &Inst) { bool InstCombiner::SimplifyDemandedBits(Use &U, APInt DemandedMask, APInt &KnownZero, APInt &KnownOne, unsigned Depth) { - Value *NewVal = - SimplifyDemandedUseBits(U.get(), DemandedMask, KnownZero, KnownOne, Depth, - dyn_cast<Instruction>(U.getUser())); + auto *UserI = dyn_cast<Instruction>(U.getUser()); + Value *NewVal = SimplifyDemandedUseBits(U.get(), DemandedMask, KnownZero, + KnownOne, Depth, UserI); if (!NewVal) return false; U = NewVal; + + // Shrinking a constant might cause a nsw/nuw violation to occur in + // instructions which are themselves demanded. + if (auto *UserOBO = dyn_cast<OverflowingBinaryOperator>(UserI)) { + cast<BinaryOperator>(UserOBO)->setHasNoSignedWrap(false); + cast<BinaryOperator>(UserOBO)->setHasNoUnsignedWrap(false); + } return true; } |