Skip to content

Commit 9593cde

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

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,11 +779,9 @@ define i64 @evaluate_zexted_const_expr(i1 %c) {
779779
ret i64 %ext
780780
}
781781

782-
; FIXME: This is currently miscompiling as the and gets dropped,
783-
; but the flag on the zext doesn't.
784782
define i16 @zext_nneg_flag_drop(i8 %x, i16 %y) {
785783
; CHECK-LABEL: @zext_nneg_flag_drop(
786-
; CHECK-NEXT: [[EXT:%.*]] = zext nneg i8 [[X:%.*]] to i16
784+
; CHECK-NEXT: [[EXT:%.*]] = zext i8 [[X:%.*]] to i16
787785
; CHECK-NEXT: [[OR1:%.*]] = or i16 [[EXT]], [[Y:%.*]]
788786
; CHECK-NEXT: [[OR2:%.*]] = or i16 [[OR1]], 128
789787
; CHECK-NEXT: ret i16 [[OR2]]

0 commit comments

Comments
 (0)