Skip to content

Commit 68e75ee

Browse files
authored
[PPC] Custom lower ssubo for i64 (llvm#118711)
This is a follow-up patch to improve the codegen for ssubo node for i64 in 64-bit mode by custom lowering.
1 parent 426aecb commit 68e75ee

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,11 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
200200

201201
// On P10, the default lowering generates better code using the
202202
// setbc instruction.
203-
if (!Subtarget.hasP10Vector())
203+
if (!Subtarget.hasP10Vector()) {
204204
setOperationAction(ISD::SSUBO, MVT::i32, Custom);
205+
if (isPPC64)
206+
setOperationAction(ISD::SSUBO, MVT::i64, Custom);
207+
}
205208

206209
// Match BITREVERSE to customized fast code sequence in the td file.
207210
setOperationAction(ISD::BITREVERSE, MVT::i32, Legal);
@@ -12051,16 +12054,19 @@ SDValue PPCTargetLowering::LowerSSUBO(SDValue Op, SelectionDAG &DAG) const {
1205112054
SDLoc dl(Op);
1205212055
SDValue LHS = Op.getOperand(0);
1205312056
SDValue RHS = Op.getOperand(1);
12057+
EVT VT = Op.getNode()->getValueType(0);
12058+
12059+
SDValue Sub = DAG.getNode(ISD::SUB, dl, VT, LHS, RHS);
1205412060

12055-
SDValue Sub = DAG.getNode(ISD::SUB, dl, MVT::i32, LHS, RHS);
12061+
SDValue Xor1 = DAG.getNode(ISD::XOR, dl, VT, RHS, LHS);
12062+
SDValue Xor2 = DAG.getNode(ISD::XOR, dl, VT, Sub, LHS);
1205612063

12057-
SDValue Xor1 = DAG.getNode(ISD::XOR, dl, MVT::i32, RHS, LHS);
12058-
SDValue Xor2 = DAG.getNode(ISD::XOR, dl, MVT::i32, Sub, LHS);
12064+
SDValue And = DAG.getNode(ISD::AND, dl, VT, Xor1, Xor2);
1205912065

12060-
SDValue And = DAG.getNode(ISD::AND, dl, MVT::i32, Xor1, Xor2);
12066+
SDValue Overflow =
12067+
DAG.getNode(ISD::SRL, dl, VT, And,
12068+
DAG.getConstant(VT.getSizeInBits() - 1, dl, MVT::i32));
1206112069

12062-
SDValue Overflow = DAG.getNode(ISD::SRL, dl, MVT::i32, And,
12063-
DAG.getConstant(31, dl, MVT::i32));
1206412070
SDValue OverflowTrunc =
1206512071
DAG.getNode(ISD::TRUNCATE, dl, Op.getNode()->getValueType(1), Overflow);
1206612072

llvm/test/CodeGen/PowerPC/saddo-ssubo.ll

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,11 @@ entry:
144144
define i1 @test_ssubo_i64(i64 %a, i64 %b) nounwind {
145145
; CHECK-LABEL: test_ssubo_i64:
146146
; CHECK: # %bb.0: # %entry
147-
; CHECK-NEXT: sub 5, 3, 4
148-
; CHECK-NEXT: cmpdi 1, 4, 0
149-
; CHECK-NEXT: cmpd 5, 3
150-
; CHECK-NEXT: li 3, 1
151-
; CHECK-NEXT: creqv 20, 5, 0
152-
; CHECK-NEXT: isel 3, 0, 3, 20
147+
; CHECK-NEXT: xor 5, 4, 3
148+
; CHECK-NEXT: sub 4, 3, 4
149+
; CHECK-NEXT: xor 3, 4, 3
150+
; CHECK-NEXT: and 3, 5, 3
151+
; CHECK-NEXT: rldicl 3, 3, 1, 63
153152
; CHECK-NEXT: blr
154153
entry:
155154
%res = call { i64, i1 } @llvm.ssub.with.overflow.i64(i64 %a, i64 %b) nounwind

0 commit comments

Comments
 (0)