1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[InstCombine] drop poison flags when simplifying 'shl' based on demanded bits

As with other transforms in demanded bits, we must be careful not to
wrongly propagate nsw/nuw if we are reducing values leading up to the shift.

This bug was introduced with 1b24f35f843c and leads to the miscompile
shown in:
https://llvm.org/PR50341
This commit is contained in:
Sanjay Patel 2021-05-14 13:41:14 -04:00
parent c9d2ef0f8c
commit 6cacbbe0b7
2 changed files with 5 additions and 2 deletions

View File

@ -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);
}

View File

@ -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]]
;