Skip to content

Commit

Permalink
[LegalizeTypes] Avoid creating an unused node in ExpandIntRes_ADDSUB.…
Browse files Browse the repository at this point in the history
… NFC

The Hi result is sometimes calculated a different way and this
node goes unused. Defer creation until we know for sure it is neeeded.

The test changes is because the node creation order changed the names
in the debug output.
  • Loading branch information
topperc committed Sep 10, 2024
1 parent ae5f1a7 commit d2f25e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3496,7 +3496,6 @@ void DAGTypeLegalizer::ExpandIntRes_ADDSUB(SDNode *N,

if (N->getOpcode() == ISD::ADD) {
Lo = DAG.getNode(ISD::ADD, dl, NVT, LoOps);
Hi = DAG.getNode(ISD::ADD, dl, NVT, ArrayRef(HiOps, 2));
SDValue Cmp;
// Special case: X+1 has a carry out if X+1==0. This may reduce the live
// range of X. We assume comparing with 0 is cheap.
Expand All @@ -3521,10 +3520,12 @@ void DAGTypeLegalizer::ExpandIntRes_ADDSUB(SDNode *N,
Carry = DAG.getSelect(dl, NVT, Cmp, DAG.getConstant(1, dl, NVT),
DAG.getConstant(0, dl, NVT));

if (isAllOnesConstant(LoOps[1]) && isAllOnesConstant(HiOps[1]))
if (isAllOnesConstant(LoOps[1]) && isAllOnesConstant(HiOps[1])) {
Hi = DAG.getNode(ISD::SUB, dl, NVT, HiOps[0], Carry);
else
} else {
Hi = DAG.getNode(ISD::ADD, dl, NVT, ArrayRef(HiOps, 2));
Hi = DAG.getNode(ISD::ADD, dl, NVT, Hi, Carry);
}
} else {
Lo = DAG.getNode(ISD::SUB, dl, NVT, LoOps);
Hi = DAG.getNode(ISD::SUB, dl, NVT, ArrayRef(HiOps, 2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ define i64 @i64_test(i64 %i) nounwind readnone {
; CHECK-NEXT: t24: i32 = ADD_R t5, t22, TargetConstant:i32<0>
; CHECK-NEXT: t3: i32,ch = LDW_RI<Mem:(load (s32) from %fixed-stack.1, align 8)> TargetFrameIndex:i32<-1>, TargetConstant:i32<0>, TargetConstant:i32<0>, t0
; CHECK-NEXT: t19: i32,ch = LDW_RI<Mem:(dereferenceable load (s32) from %ir.loc, align 8)> TargetFrameIndex:i32<0>, TargetConstant:i32<0>, TargetConstant:i32<0>, t0
; CHECK-NEXT: t25: i32 = ADD_R t3, t19, TargetConstant:i32<0>
; CHECK-NEXT: t27: i32 = ADD_R t3, t19, TargetConstant:i32<0>
; CHECK-NEXT: t30: i32,glue = SFSUB_F_RR t24, t5
; CHECK-NEXT: t31: i32 = SCC TargetConstant:i32<4>, t30:1
; CHECK-NEXT: t28: i32 = ADD_R t25, t31, TargetConstant:i32<0>
; CHECK-NEXT: t28: i32 = ADD_R t27, t31, TargetConstant:i32<0>
; CHECK-NEXT: t15: ch,glue = CopyToReg t0, Register:i32 $rv, t28
; CHECK-NEXT: t17: ch,glue = CopyToReg t15, Register:i32 $r9, t24, t15:1
; CHECK-NEXT: t18: ch = RET Register:i32 $rv, Register:i32 $r9, t17, t17:1
Expand Down

0 comments on commit d2f25e5

Please sign in to comment.