Skip to content

Commit 52981c1

Browse files
committed
[TargetLowering] Drop nuw/nsw flags in TargetLowering::SimplifyDemandedBits
1 parent 1e928cd commit 52981c1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2598,14 +2598,23 @@ bool TargetLowering::SimplifyDemandedBits(
25982598
}
25992599
case ISD::TRUNCATE: {
26002600
SDValue Src = Op.getOperand(0);
2601+
SDNodeFlags Flags = Op->getFlags();
26012602

26022603
// Simplify the input, using demanded bit information, and compute the known
26032604
// zero/one bits live out.
26042605
unsigned OperandBitWidth = Src.getScalarValueSizeInBits();
26052606
APInt TruncMask = DemandedBits.zext(OperandBitWidth);
26062607
if (SimplifyDemandedBits(Src, TruncMask, DemandedElts, Known, TLO,
2607-
Depth + 1))
2608+
Depth + 1)) {
2609+
if (Flags.hasNoSignedWrap() || Flags.hasNoUnsignedWrap()) {
2610+
// Disable the nsw and nuw flags. We can no longer guarantee that we
2611+
// won't wrap after simplification.
2612+
Flags.setNoSignedWrap(false);
2613+
Flags.setNoUnsignedWrap(false);
2614+
Op->setFlags(Flags);
2615+
}
26082616
return true;
2617+
}
26092618
Known = Known.trunc(BitWidth);
26102619

26112620
// Attempt to avoid multi-use ops if we don't need anything from them.

llvm/test/CodeGen/X86/trunc-nsw-nuw.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ entry:
6262
define i32 @simplify_demanded_bits_drop_flag(i1 zeroext %x, i1 zeroext %y) nounwind {
6363
; CHECK-LABEL: simplify_demanded_bits_drop_flag:
6464
; CHECK: # %bb.0: # %entry
65-
; CHECK-NEXT: # kill: def $esi killed $esi def $rsi
6665
; CHECK-NEXT: negl %edi
6766
; CHECK-NEXT: shll $2, %esi
6867
; CHECK-NEXT: xorl %edi, %esi
69-
; CHECK-NEXT: imulq $-1634202141, %rsi, %rax # imm = 0x9E980DE3
68+
; CHECK-NEXT: movslq %esi, %rax
69+
; CHECK-NEXT: imulq $-1634202141, %rax, %rax # imm = 0x9E980DE3
7070
; CHECK-NEXT: movq %rax, %rcx
7171
; CHECK-NEXT: shrq $63, %rcx
7272
; CHECK-NEXT: sarq $44, %rax

0 commit comments

Comments
 (0)