[PATCH] D129708: [PowerPC] Add an ISEL pattern for i32 MULLI.
Esme Yi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 13 17:29:09 PDT 2022
Esme created this revision.
Esme added reviewers: shchenz, PowerPC.
Herald added subscribers: kbarton, hiraditya, nemanjai.
Herald added a project: All.
Esme requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
We add the following ISEL pattern for i64 imm in D87384 <https://reviews.llvm.org/D87384>, this patch is for i32.
mul with (2^N * int16_imm) -> MULLI + RLWINM
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129708
Files:
llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
llvm/test/CodeGen/PowerPC/mulli.ll
Index: llvm/test/CodeGen/PowerPC/mulli.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/mulli.ll
+++ llvm/test/CodeGen/PowerPC/mulli.ll
@@ -119,9 +119,8 @@
define i32 @test11(i32 %x) {
; CHECK-LABEL: test11:
; CHECK: # %bb.0:
-; CHECK-NEXT: lis 4, 10
-; CHECK-NEXT: ori 4, 4, 43680
-; CHECK-NEXT: mullw 3, 3, 4
+; CHECK-NEXT: mulli 3, 3, 21845
+; CHECK-NEXT: slwi 3, 3, 5
; CHECK-NEXT: blr
%y = mul nsw i32 %x, 699040
ret i32 %y
Index: llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
+++ llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
@@ -5484,7 +5484,8 @@
}
case ISD::MUL: {
SDValue Op1 = N->getOperand(1);
- if (Op1.getOpcode() != ISD::Constant || Op1.getValueType() != MVT::i64)
+ if (Op1.getOpcode() != ISD::Constant ||
+ (Op1.getValueType() != MVT::i64 && Op1.getValueType() != MVT::i32))
break;
// If the multiplier fits int16, we can handle it with mulli.
@@ -5497,13 +5498,27 @@
// (mul X, c1 << c2) -> (rldicr (mulli X, c1) c2). We do this in ISEL due to
// DAGCombiner prefers (shl (mul X, c1), c2) -> (mul X, c1 << c2).
uint64_t ImmSh = Imm >> Shift;
- if (isInt<16>(ImmSh)) {
- uint64_t SextImm = SignExtend64(ImmSh & 0xFFFF, 16);
+ if (!isInt<16>(ImmSh))
+ break;
+
+ uint64_t SextImm = SignExtend64(ImmSh & 0xFFFF, 16);
+ if (Op1.getValueType() == MVT::i64) {
SDValue SDImm = CurDAG->getTargetConstant(SextImm, dl, MVT::i64);
SDNode *MulNode = CurDAG->getMachineNode(PPC::MULLI8, dl, MVT::i64,
N->getOperand(0), SDImm);
- CurDAG->SelectNodeTo(N, PPC::RLDICR, MVT::i64, SDValue(MulNode, 0),
- getI32Imm(Shift, dl), getI32Imm(63 - Shift, dl));
+
+ SDValue Ops[] = {SDValue(MulNode, 0), getI32Imm(Shift, dl),
+ getI32Imm(63 - Shift, dl)};
+ CurDAG->SelectNodeTo(N, PPC::RLDICR, MVT::i64, Ops);
+ return;
+ } else {
+ SDValue SDImm = CurDAG->getTargetConstant(SextImm, dl, MVT::i32);
+ SDNode *MulNode = CurDAG->getMachineNode(PPC::MULLI, dl, MVT::i32,
+ N->getOperand(0), SDImm);
+
+ SDValue Ops[] = {SDValue(MulNode, 0), getI32Imm(Shift, dl),
+ getI32Imm(0, dl), getI32Imm(31 - Shift, dl)};
+ CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops);
return;
}
break;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129708.444468.patch
Type: text/x-patch
Size: 2582 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220714/8f037e09/attachment.bin>
More information about the llvm-commits
mailing list