Skip to content

Commit

Permalink
[instcombine] Drop zext nneg flag when simplify operand
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
preames committed Nov 2, 2023
1 parent 3b589fe commit 26f6ec3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,12 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,

APInt InputDemandedMask = DemandedMask.zextOrTrunc(SrcBitWidth);
KnownBits InputKnown(SrcBitWidth);
if (SimplifyDemandedBits(I, 0, InputDemandedMask, InputKnown, Depth + 1))
if (SimplifyDemandedBits(I, 0, InputDemandedMask, InputKnown, Depth + 1)) {
// For zext nneg, we may have dropped the instruction which made the
// input non-negative.
I->dropPoisonGeneratingFlags();
return I;
}
assert(InputKnown.getBitWidth() == SrcBitWidth && "Src width changed?");
Known = InputKnown.zextOrTrunc(BitWidth);
assert(!Known.hasConflict() && "Bits known to be one AND zero?");
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/InstCombine/zext.ll
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ define i64 @evaluate_zexted_const_expr(i1 %c) {
; but the flag on the zext doesn't.
define i16 @zext_nneg_flag_drop(i8 %x, i16 %y) {
; CHECK-LABEL: @zext_nneg_flag_drop(
; CHECK-NEXT: [[EXT:%.*]] = zext nneg i8 [[X:%.*]] to i16
; CHECK-NEXT: [[EXT:%.*]] = zext i8 [[X:%.*]] to i16
; CHECK-NEXT: [[OR1:%.*]] = or i16 [[EXT]], [[Y:%.*]]
; CHECK-NEXT: [[OR2:%.*]] = or i16 [[OR1]], 128
; CHECK-NEXT: ret i16 [[OR2]]
Expand Down

0 comments on commit 26f6ec3

Please sign in to comment.