Skip to content

Commit 2ba1428

Browse files
committed
Revert "[SelectionDAG] Handle NSW for ADD/SUB in computeKnownBits()"
This reverts commit b665513. This has exposed a pre-existing miscompile, reported in https://reviews.llvm.org/D150769#4370467.
1 parent 2e6325c commit 2ba1428

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3631,15 +3631,6 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
36313631
// All bits are zero except the low bit.
36323632
Known.Zero.setBitsFrom(1);
36333633
break;
3634-
case ISD::ADD:
3635-
case ISD::SUB: {
3636-
SDNodeFlags Flags = Op.getNode()->getFlags();
3637-
Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
3638-
Known2 = computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1);
3639-
Known = KnownBits::computeForAddSub(Op.getOpcode() == ISD::ADD,
3640-
Flags.hasNoSignedWrap(), Known, Known2);
3641-
break;
3642-
}
36433634
case ISD::USUBO:
36443635
case ISD::SSUBO:
36453636
case ISD::USUBO_CARRY:
@@ -3653,6 +3644,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
36533644
break;
36543645
}
36553646
[[fallthrough]];
3647+
case ISD::SUB:
36563648
case ISD::SUBC: {
36573649
assert(Op.getResNo() == 0 &&
36583650
"We only compute knownbits for the difference here.");
@@ -3680,6 +3672,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
36803672
break;
36813673
}
36823674
[[fallthrough]];
3675+
case ISD::ADD:
36833676
case ISD::ADDC:
36843677
case ISD::ADDE: {
36853678
assert(Op.getResNo() == 0 && "We only compute knownbits for the sum here.");

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,9 +2694,11 @@ bool TargetLowering::SimplifyDemandedBits(
26942694
if (Op.getOpcode() == ISD::MUL) {
26952695
Known = KnownBits::mul(KnownOp0, KnownOp1);
26962696
} else { // Op.getOpcode() is either ISD::ADD or ISD::SUB.
2697-
Known = KnownBits::computeForAddSub(Op.getOpcode() == ISD::ADD,
2698-
Flags.hasNoSignedWrap(), KnownOp0,
2699-
KnownOp1);
2697+
// TODO: Update `computeForAddCarry` to handle the NSW flag as well so
2698+
// that `Flags.hasNoSignedWrap()` can be passed through here
2699+
// instead of false.
2700+
Known = KnownBits::computeForAddSub(Op.getOpcode() == ISD::ADD, false,
2701+
KnownOp0, KnownOp1);
27002702
}
27012703
break;
27022704
}

llvm/test/CodeGen/Thumb2/mve-blockplacement.ll

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,16 +366,18 @@ define i32 @d(i64 %e, i32 %f, i64 %g, i32 %h) {
366366
; CHECK-NEXT: str r0, [sp, #12] @ 4-byte Spill
367367
; CHECK-NEXT: movs r1, #4
368368
; CHECK-NEXT: strd r2, r12, [sp, #4] @ 8-byte Folded Spill
369-
; CHECK-NEXT: add.w r1, r1, r4, lsr #1
370369
; CHECK-NEXT: add.w r3, r3, r4, lsr #1
371-
; CHECK-NEXT: bic r7, r1, #3
370+
; CHECK-NEXT: add.w r1, r1, r4, lsr #1
371+
; CHECK-NEXT: movw r4, #65532
372+
; CHECK-NEXT: vdup.32 q6, r3
373+
; CHECK-NEXT: movt r4, #32767
374+
; CHECK-NEXT: and.w r7, r1, r4
372375
; CHECK-NEXT: adr r1, .LCPI1_0
376+
; CHECK-NEXT: vdup.32 q7, r3
373377
; CHECK-NEXT: vldrw.u32 q0, [r1]
374378
; CHECK-NEXT: adr r1, .LCPI1_1
375379
; CHECK-NEXT: vldrw.u32 q5, [r1]
376-
; CHECK-NEXT: vdup.32 q6, r3
377380
; CHECK-NEXT: vadd.i32 q4, q0, lr
378-
; CHECK-NEXT: vdup.32 q7, r3
379381
; CHECK-NEXT: b .LBB1_4
380382
; CHECK-NEXT: .LBB1_2: @ %for.body6.preheader
381383
; CHECK-NEXT: @ in Loop: Header=BB1_4 Depth=1

0 commit comments

Comments
 (0)