Skip to content

Commit 263b1d4

Browse files
committed
[TargetLowering] Drop nuw/nsw flags in TargetLowering::SimplifyDemandedBits
1 parent 59b1e6d commit 263b1d4

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
@@ -2552,14 +2552,23 @@ bool TargetLowering::SimplifyDemandedBits(
25522552
}
25532553
case ISD::TRUNCATE: {
25542554
SDValue Src = Op.getOperand(0);
2555+
SDNodeFlags Flags = Op->getFlags();
25552556

25562557
// Simplify the input, using demanded bit information, and compute the known
25572558
// zero/one bits live out.
25582559
unsigned OperandBitWidth = Src.getScalarValueSizeInBits();
25592560
APInt TruncMask = DemandedBits.zext(OperandBitWidth);
25602561
if (SimplifyDemandedBits(Src, TruncMask, DemandedElts, Known, TLO,
2561-
Depth + 1))
2562+
Depth + 1)) {
2563+
if (Flags.hasNoSignedWrap() || Flags.hasNoUnsignedWrap()) {
2564+
// Disable the nsw and nuw flags. We can no longer guarantee that we
2565+
// won't wrap after simplification.
2566+
Flags.setNoSignedWrap(false);
2567+
Flags.setNoUnsignedWrap(false);
2568+
Op->setFlags(Flags);
2569+
}
25622570
return true;
2571+
}
25632572
Known = Known.trunc(BitWidth);
25642573

25652574
// 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)