Skip to content

Commit f71a9e8

Browse files
authored
[SelectionDAG][RISCV][PowerPC][X86] Use TargetConstant for immediates for ISD::PREFETCH. (#66601)
The intrinsic uses ImmArg so TargetConstant would be consistent with how other intrinsics are handled. This hides the constants from type legalization so we can remove the promotion support. isel patterns are updated accordingly.
1 parent 39f1860 commit f71a9e8

File tree

8 files changed

+22
-34
lines changed

8 files changed

+22
-34
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,8 +1818,6 @@ bool DAGTypeLegalizer::PromoteIntegerOperand(SDNode *N, unsigned OpNo) {
18181818
case ISD::FRAMEADDR:
18191819
case ISD::RETURNADDR: Res = PromoteIntOp_FRAMERETURNADDR(N); break;
18201820

1821-
case ISD::PREFETCH: Res = PromoteIntOp_PREFETCH(N, OpNo); break;
1822-
18231821
case ISD::SMULFIX:
18241822
case ISD::SMULFIXSAT:
18251823
case ISD::UMULFIX:
@@ -2333,18 +2331,6 @@ SDValue DAGTypeLegalizer::PromoteIntOp_FRAMERETURNADDR(SDNode *N) {
23332331
return SDValue(DAG.UpdateNodeOperands(N, Op), 0);
23342332
}
23352333

2336-
SDValue DAGTypeLegalizer::PromoteIntOp_PREFETCH(SDNode *N, unsigned OpNo) {
2337-
assert(OpNo > 1 && "Don't know how to promote this operand!");
2338-
// Promote the rw, locality, and cache type arguments to a supported integer
2339-
// width.
2340-
SDValue Op2 = ZExtPromotedInteger(N->getOperand(2));
2341-
SDValue Op3 = ZExtPromotedInteger(N->getOperand(3));
2342-
SDValue Op4 = ZExtPromotedInteger(N->getOperand(4));
2343-
return SDValue(DAG.UpdateNodeOperands(N, N->getOperand(0), N->getOperand(1),
2344-
Op2, Op3, Op4),
2345-
0);
2346-
}
2347-
23482334
SDValue DAGTypeLegalizer::PromoteIntOp_ExpOp(SDNode *N) {
23492335
bool IsStrict = N->isStrictFPOpcode();
23502336
SDValue Chain = IsStrict ? N->getOperand(0) : SDValue();

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
401401
SDValue PromoteIntOp_MGATHER(MaskedGatherSDNode *N, unsigned OpNo);
402402
SDValue PromoteIntOp_ADDSUBO_CARRY(SDNode *N, unsigned OpNo);
403403
SDValue PromoteIntOp_FRAMERETURNADDR(SDNode *N);
404-
SDValue PromoteIntOp_PREFETCH(SDNode *N, unsigned OpNo);
405404
SDValue PromoteIntOp_FIX(SDNode *N);
406405
SDValue PromoteIntOp_ExpOp(SDNode *N);
407406
SDValue PromoteIntOp_VECREDUCE(SDNode *N);

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7089,9 +7089,12 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
70897089
auto Flags = rw == 0 ? MachineMemOperand::MOLoad :MachineMemOperand::MOStore;
70907090
Ops[0] = DAG.getRoot();
70917091
Ops[1] = getValue(I.getArgOperand(0));
7092-
Ops[2] = getValue(I.getArgOperand(1));
7093-
Ops[3] = getValue(I.getArgOperand(2));
7094-
Ops[4] = getValue(I.getArgOperand(3));
7092+
Ops[2] = DAG.getTargetConstant(*cast<ConstantInt>(I.getArgOperand(1)), sdl,
7093+
MVT::i32);
7094+
Ops[3] = DAG.getTargetConstant(*cast<ConstantInt>(I.getArgOperand(2)), sdl,
7095+
MVT::i32);
7096+
Ops[4] = DAG.getTargetConstant(*cast<ConstantInt>(I.getArgOperand(3)), sdl,
7097+
MVT::i32);
70957098
SDValue Result = DAG.getMemIntrinsicNode(
70967099
ISD::PREFETCH, sdl, DAG.getVTList(MVT::Other), Ops,
70977100
EVT::getIntegerVT(*Context, 8), MachinePointerInfo(I.getArgOperand(0)),

llvm/lib/Target/PowerPC/PPCInstrInfo.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,11 +1713,11 @@ def : Pat<(int_ppc_dcbf xoaddr:$dst),
17131713
def : Pat<(int_ppc_icbt xoaddr:$dst),
17141714
(ICBT 0, xoaddr:$dst)>;
17151715

1716-
def : Pat<(prefetch xoaddr:$dst, (i32 0), imm, (i32 1)),
1716+
def : Pat<(prefetch xoaddr:$dst, (i32 0), timm, (i32 1)),
17171717
(DCBT 0, xoaddr:$dst)>; // data prefetch for loads
1718-
def : Pat<(prefetch xoaddr:$dst, (i32 1), imm, (i32 1)),
1718+
def : Pat<(prefetch xoaddr:$dst, (i32 1), timm, (i32 1)),
17191719
(DCBTST 0, xoaddr:$dst)>; // data prefetch for stores
1720-
def : Pat<(prefetch xoaddr:$dst, (i32 0), imm, (i32 0)),
1720+
def : Pat<(prefetch xoaddr:$dst, (i32 0), timm, (i32 0)),
17211721
(ICBT 0, xoaddr:$dst)>, Requires<[HasICBT]>; // inst prefetch (for read)
17221722

17231723
def : Pat<(int_ppc_dcbt_with_hint xoaddr:$dst, i32:$TH),

llvm/lib/Target/RISCV/RISCVInstrInfoZicbo.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ def PREFETCH_W : Prefetch_ri<0b00011, "prefetch.w">, Sched<[]>;
7676

7777
let Predicates = [HasStdExtZicbop] in {
7878
// FIXME: Match address with offset
79-
def : Pat<(prefetch GPR:$rs1, imm, imm, (XLenVT 0)),
79+
def : Pat<(prefetch GPR:$rs1, timm, timm, (i32 0)),
8080
(PREFETCH_I GPR:$rs1, 0)>;
81-
def : Pat<(prefetch GPR:$rs1, (XLenVT 0), imm, (XLenVT 1)),
81+
def : Pat<(prefetch GPR:$rs1, (i32 0), timm, (i32 1)),
8282
(PREFETCH_R GPR:$rs1, 0)>;
83-
def : Pat<(prefetch GPR:$rs1, (XLenVT 1), imm, (XLenVT 1)),
83+
def : Pat<(prefetch GPR:$rs1, (i32 1), timm, (i32 1)),
8484
(PREFETCH_W GPR:$rs1, 0)>;
8585
}

llvm/lib/Target/X86/X86Instr3DNow.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,20 @@ def FEMMS : I3DNow<0x0E, RawFrm, (outs), (ins), "femms",
8080
[(int_x86_mmx_femms)]>, TB;
8181

8282
// PREFETCHWT1 is supported we want to use it for everything but T0.
83-
def PrefetchWLevel : PatFrag<(ops), (i32 imm), [{
83+
def PrefetchWLevel : PatFrag<(ops), (i32 timm), [{
8484
return N->getSExtValue() == 3 || !Subtarget->hasPREFETCHWT1();
8585
}]>;
8686

8787
// Use PREFETCHWT1 for NTA, T2, T1.
88-
def PrefetchWT1Level : ImmLeaf<i32, [{
88+
def PrefetchWT1Level : TImmLeaf<i32, [{
8989
return Imm < 3;
9090
}]>;
9191

9292
let SchedRW = [WriteLoad] in {
9393
let Predicates = [Has3DNow, NoSSEPrefetch] in
9494
def PREFETCH : I3DNow<0x0D, MRM0m, (outs), (ins i8mem:$addr),
9595
"prefetch\t$addr",
96-
[(prefetch addr:$addr, imm, imm, (i32 1))]>, TB;
96+
[(prefetch addr:$addr, timm, timm, (i32 1))]>, TB;
9797

9898
def PREFETCHW : I<0x0D, MRM1m, (outs), (ins i8mem:$addr), "prefetchw\t$addr",
9999
[(prefetch addr:$addr, (i32 1), (i32 PrefetchWLevel), (i32 1))]>,

llvm/lib/Target/X86/X86InstrSSE.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,13 +3212,13 @@ let Predicates = [UseSSE2] in {
32123212
// Prefetch intrinsic.
32133213
let Predicates = [HasSSEPrefetch], SchedRW = [WriteLoad] in {
32143214
def PREFETCHT0 : I<0x18, MRM1m, (outs), (ins i8mem:$src),
3215-
"prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3), (i32 1))]>, TB;
3215+
"prefetcht0\t$src", [(prefetch addr:$src, timm, (i32 3), (i32 1))]>, TB;
32163216
def PREFETCHT1 : I<0x18, MRM2m, (outs), (ins i8mem:$src),
3217-
"prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2), (i32 1))]>, TB;
3217+
"prefetcht1\t$src", [(prefetch addr:$src, timm, (i32 2), (i32 1))]>, TB;
32183218
def PREFETCHT2 : I<0x18, MRM3m, (outs), (ins i8mem:$src),
3219-
"prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1), (i32 1))]>, TB;
3219+
"prefetcht2\t$src", [(prefetch addr:$src, timm, (i32 1), (i32 1))]>, TB;
32203220
def PREFETCHNTA : I<0x18, MRM0m, (outs), (ins i8mem:$src),
3221-
"prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0), (i32 1))]>, TB;
3221+
"prefetchnta\t$src", [(prefetch addr:$src, timm, (i32 0), (i32 1))]>, TB;
32223222
}
32233223

32243224
// FIXME: How should flush instruction be modeled?

llvm/test/CodeGen/PowerPC/ppc64-icbt-pwr7.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ entry:
1111

1212
; FIXME: Crashing is not really the correct behavior here, we really should just emit nothing
1313
; CHECK: Cannot select: {{0x[0-9,a-f]+|t[0-9]+}}: ch = Prefetch
14-
; CHECK: {{0x[0-9,a-f]+|t[0-9]+}}: i32 = Constant<0>
15-
; CHECK-NEXT: {{0x[0-9,a-f]+|t[0-9]+}}: i32 = Constant<3>
16-
; CHECK-NEXT: {{0x[0-9,a-f]+|t[0-9]+}}: i32 = Constant<0>
14+
; CHECK: {{0x[0-9,a-f]+|t[0-9]+}}: i32 = TargetConstant<0>
15+
; CHECK-NEXT: {{0x[0-9,a-f]+|t[0-9]+}}: i32 = TargetConstant<3>
16+
; CHECK-NEXT: {{0x[0-9,a-f]+|t[0-9]+}}: i32 = TargetConstant<0>
1717

1818
}
1919

0 commit comments

Comments
 (0)