diff --git a/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 2b9c1f2ad3d..89575989255 100644 --- a/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -575,8 +575,11 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, // demanding those bits from the pre-shifted operand either. if (unsigned CTLZ = DemandedMask.countLeadingZeros()) { APInt DemandedFromOp(APInt::getLowBitsSet(BitWidth, BitWidth - CTLZ)); - if (SimplifyDemandedBits(I, 0, DemandedFromOp, Known, Depth + 1)) + if (SimplifyDemandedBits(I, 0, DemandedFromOp, Known, Depth + 1)) { + // We can't guarantee that nsw/nuw hold after simplifying the operand. + I->dropPoisonGeneratingFlags(); return I; + } } computeKnownBits(I, Known, Depth, CxtI); } diff --git a/test/Transforms/InstCombine/shl-demand.ll b/test/Transforms/InstCombine/shl-demand.ll index 245c7033190..11c2de8e58d 100644 --- a/test/Transforms/InstCombine/shl-demand.ll +++ b/test/Transforms/InstCombine/shl-demand.ll @@ -89,7 +89,7 @@ define i32 @set_shl_mask(i32 %x, i32 %y) { define i8 @must_drop_poison(i32 %x, i32 %y) { ; CHECK-LABEL: @must_drop_poison( -; CHECK-NEXT: [[S:%.*]] = shl nuw nsw i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[S:%.*]] = shl i32 [[X:%.*]], [[Y:%.*]] ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[S]] to i8 ; CHECK-NEXT: ret i8 [[T]] ;