Skip to content

Commit 022aefa

Browse files
committed
[X86] Don't crash on instruction prefetch intrinsics without PREFETCHI support.
Instead of failing to select during isel, drop the intrinsic in lowering. Fixes PR62839. Reviewed By: pengfei Differential Revision: https://reviews.llvm.org/D151050
1 parent 3303195 commit 022aefa

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
529529
}
530530

531531
if (Subtarget.hasSSEPrefetch() || Subtarget.hasThreeDNow())
532-
setOperationAction(ISD::PREFETCH , MVT::Other, Legal);
532+
setOperationAction(ISD::PREFETCH , MVT::Other, Custom);
533533

534534
setOperationAction(ISD::ATOMIC_FENCE , MVT::Other, Custom);
535535

@@ -33984,6 +33984,18 @@ static SDValue LowerCVTPS2PH(SDValue Op, SelectionDAG &DAG) {
3398433984
return DAG.getNode(ISD::CONCAT_VECTORS, dl, VT, Lo, Hi);
3398533985
}
3398633986

33987+
static SDValue LowerPREFETCH(SDValue Op, const X86Subtarget &Subtarget,
33988+
SelectionDAG &DAG) {
33989+
unsigned IsData = cast<ConstantSDNode>(Op.getOperand(4))->getZExtValue();
33990+
33991+
// We don't support non-data prefetch without PREFETCHI.
33992+
// Just preserve the chain.
33993+
if (!IsData && !Subtarget.hasPREFETCHI())
33994+
return Op.getOperand(0);
33995+
33996+
return Op;
33997+
}
33998+
3398733999
static StringRef getInstrStrFromOpNo(const SmallVectorImpl<StringRef> &AsmStrs,
3398834000
unsigned OpNo) {
3398934001
const APInt Operand(32, OpNo);
@@ -34188,6 +34200,7 @@ SDValue X86TargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
3418834200
case ISD::GC_TRANSITION_END: return LowerGC_TRANSITION(Op, DAG);
3418934201
case ISD::ADDRSPACECAST: return LowerADDRSPACECAST(Op, DAG);
3419034202
case X86ISD::CVTPS2PH: return LowerCVTPS2PH(Op, DAG);
34203+
case ISD::PREFETCH: return LowerPREFETCH(Op, Subtarget, DAG);
3419134204
}
3419234205
}
3419334206

llvm/test/CodeGen/X86/prefetchi.ll

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
22
; RUN: llc < %s -mtriple=x86_64-- -mattr=+prefetchi | FileCheck %s
3+
; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s --check-prefix=NOPREFETCHI
34

45
define dso_local void @t(ptr %ptr) nounwind {
56
; CHECK-LABEL: t:
@@ -9,6 +10,10 @@ define dso_local void @t(ptr %ptr) nounwind {
910
; CHECK-NEXT: prefetchit1 t(%rip)
1011
; CHECK-NEXT: prefetchit0 ext(%rip)
1112
; CHECK-NEXT: retq
13+
;
14+
; NOPREFETCHI-LABEL: t:
15+
; NOPREFETCHI: # %bb.0: # %entry
16+
; NOPREFETCHI-NEXT: retq
1217
entry:
1318
tail call void @llvm.prefetch(ptr %ptr, i32 0, i32 2, i32 0)
1419
tail call void @llvm.prefetch(ptr %ptr, i32 0, i32 3, i32 0)

0 commit comments

Comments
 (0)