From fe58d13a17a2824fe891274e1396e5fc1ca5ab38 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 22 Apr 2015 20:59:28 +0000 Subject: [InstCombine] Clear out nsw/nuw if we modify computation in the chain An nsw/nuw operation relies on the values feeding into it to not overflow if 'poison' is not to be produced. This means that optimizations which make modifications to the bottom of a chain (like SimplifyDemandedBits) must strip out nsw/nuw if they cannot ensure that they will be preserved. This fixes PR23309. llvm-svn: 235544 --- .../Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp') diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index cd391d0..0695ec1 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(U.getUser())); + auto *UserI = dyn_cast(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(UserI)) { + cast(UserOBO)->setHasNoSignedWrap(false); + cast(UserOBO)->setHasNoUnsignedWrap(false); + } return true; } -- cgit v1.1