Skip to content

Commit 26f6ec3

Browse files
committed
[instcombine] Drop zext nneg flag when simplify operand
This fixes a miscompile introduced in the recent llvm#67982, and likely exposed in changes since to infer and leverage the same. No active bug reports as of yet. This was noticed in llvm#70858 (comment).
1 parent 3b589fe commit 26f6ec3

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,12 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
422422

423423
APInt InputDemandedMask = DemandedMask.zextOrTrunc(SrcBitWidth);
424424
KnownBits InputKnown(SrcBitWidth);
425-
if (SimplifyDemandedBits(I, 0, InputDemandedMask, InputKnown, Depth + 1))
425+
if (SimplifyDemandedBits(I, 0, InputDemandedMask, InputKnown, Depth + 1)) {
426+
// For zext nneg, we may have dropped the instruction which made the
427+
// input non-negative.
428+
I->dropPoisonGeneratingFlags();
426429
return I;
430+
}
427431
assert(InputKnown.getBitWidth() == SrcBitWidth && "Src width changed?");
428432
Known = InputKnown.zextOrTrunc(BitWidth);
429433
assert(!Known.hasConflict() && "Bits known to be one AND zero?");

llvm/test/Transforms/InstCombine/zext.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ define i64 @evaluate_zexted_const_expr(i1 %c) {
783783
; but the flag on the zext doesn't.
784784
define i16 @zext_nneg_flag_drop(i8 %x, i16 %y) {
785785
; CHECK-LABEL: @zext_nneg_flag_drop(
786-
; CHECK-NEXT: [[EXT:%.*]] = zext nneg i8 [[X:%.*]] to i16
786+
; CHECK-NEXT: [[EXT:%.*]] = zext i8 [[X:%.*]] to i16
787787
; CHECK-NEXT: [[OR1:%.*]] = or i16 [[EXT]], [[Y:%.*]]
788788
; CHECK-NEXT: [[OR2:%.*]] = or i16 [[OR1]], 128
789789
; CHECK-NEXT: ret i16 [[OR2]]

0 commit comments

Comments
 (0)