Skip to content

Commit 581772e

Browse files
leecheechentstellar
authored andcommitted
[LoongArch] Don't crash on instruction prefetch intrinsics (llvm#135760)
Instead of failing to select during isel, drop the intrinsic in lowering. Similar as the X86's PR. Seeing: https://reviews.llvm.org/D151050. Fixes llvm#134624 (cherry picked from commit dfb5b6e)
1 parent 89adc2d commit 581772e

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
9999
setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::Other, Custom);
100100
setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
101101

102-
setOperationAction(ISD::PREFETCH, MVT::Other, Legal);
102+
setOperationAction(ISD::PREFETCH, MVT::Other, Custom);
103103

104104
// Expand bitreverse.i16 with native-width bitrev and shift for now, before
105105
// we get to know which of sll and revb.2h is faster.
@@ -459,10 +459,24 @@ SDValue LoongArchTargetLowering::LowerOperation(SDValue Op,
459459
return lowerBITREVERSE(Op, DAG);
460460
case ISD::SCALAR_TO_VECTOR:
461461
return lowerSCALAR_TO_VECTOR(Op, DAG);
462+
case ISD::PREFETCH:
463+
return lowerPREFETCH(Op, DAG);
462464
}
463465
return SDValue();
464466
}
465467

468+
SDValue LoongArchTargetLowering::lowerPREFETCH(SDValue Op,
469+
SelectionDAG &DAG) const {
470+
unsigned IsData = Op.getConstantOperandVal(4);
471+
472+
// We don't support non-data prefetch.
473+
// Just preserve the chain.
474+
if (!IsData)
475+
return Op.getOperand(0);
476+
477+
return Op;
478+
}
479+
466480
SDValue
467481
LoongArchTargetLowering::lowerSCALAR_TO_VECTOR(SDValue Op,
468482
SelectionDAG &DAG) const {

llvm/lib/Target/LoongArch/LoongArchISelLowering.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ class LoongArchTargetLowering : public TargetLowering {
337337
SDValue lowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
338338
SDValue lowerBITREVERSE(SDValue Op, SelectionDAG &DAG) const;
339339
SDValue lowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) const;
340+
SDValue lowerPREFETCH(SDValue Op, SelectionDAG &DAG) const;
340341

341342
bool isFPImmLegal(const APFloat &Imm, EVT VT,
342343
bool ForCodeSize) const override;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc --mtriple=loongarch32 < %s | FileCheck %s --check-prefix=LA32
3+
; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s --check-prefix=LA64
4+
5+
declare void @llvm.prefetch(ptr, i32, i32, i32) nounwind
6+
7+
define dso_local void @prefetch_no_offset(ptr %ptr) nounwind {
8+
; LA32-LABEL: prefetch_no_offset:
9+
; LA32: # %bb.0: # %entry
10+
; LA32-NEXT: ret
11+
;
12+
; LA64-LABEL: prefetch_no_offset:
13+
; LA64: # %bb.0: # %entry
14+
; LA64-NEXT: ret
15+
entry:
16+
tail call void @llvm.prefetch(ptr %ptr, i32 0, i32 3, i32 0)
17+
ret void
18+
}
19+
20+
21+
define dso_local void @prefetch_with_offset(ptr %ptr) nounwind {
22+
; LA32-LABEL: prefetch_with_offset:
23+
; LA32: # %bb.0: # %entry
24+
; LA32-NEXT: ret
25+
;
26+
; LA64-LABEL: prefetch_with_offset:
27+
; LA64: # %bb.0: # %entry
28+
; LA64-NEXT: ret
29+
entry:
30+
%addr = getelementptr i8, ptr %ptr, i64 200
31+
tail call void @llvm.prefetch(ptr %addr, i32 0, i32 3, i32 0)
32+
ret void
33+
}

0 commit comments

Comments
 (0)