[PATCH] D132042: [IR] Update llvm.prefetch to match docs

Sam Elliott via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 17 10:48:06 PDT 2022


lenary created this revision.
Herald added subscribers: frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya.
Herald added a project: All.
lenary requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, jdoerfert, MaskRay.
Herald added a project: LLVM.

The current llvm.prefetch intrinsic docs state "The rw, locality and
cache type arguments must be constant integers."

This change:

- Makes arg 3 (cache type) an ImmArg
- Improves the verifier error messages to reference the incorrect argument.
- Fixes two tests which contradict the docs.

This is needed as the lowering to GlobalISel is different for ImmArgs
compared to other constants. The non-ImmArgs create a G_CONSTANT MIR
instruction, the for ImmArgs the constant is put directly on the
intrinsic's MIR instruction as an immediate.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132042

Files:
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/IR/Verifier.cpp
  llvm/test/Assembler/auto_upgrade_intrinsics.ll
  llvm/test/CodeGen/RISCV/prefetch.ll


Index: llvm/test/CodeGen/RISCV/prefetch.ll
===================================================================
--- llvm/test/CodeGen/RISCV/prefetch.ll
+++ llvm/test/CodeGen/RISCV/prefetch.ll
@@ -14,6 +14,6 @@
 ; RV64I-LABEL: test_prefetch:
 ; RV64I:       # %bb.0:
 ; RV64I-NEXT:    ret
-  call void @llvm.prefetch(i8* %a, i32 0, i32 1, i32 2)
+  call void @llvm.prefetch(i8* %a, i32 0, i32 2, i32 1)
   ret void
 }
Index: llvm/test/Assembler/auto_upgrade_intrinsics.ll
===================================================================
--- llvm/test/Assembler/auto_upgrade_intrinsics.ll
+++ llvm/test/Assembler/auto_upgrade_intrinsics.ll
@@ -189,24 +189,24 @@
 declare void @llvm.prefetch(i8*, i32, i32, i32)
 define void @test.prefetch(i8* %ptr) {
 ; CHECK-LABEL: @test.prefetch(
-; CHECK: @llvm.prefetch.p0i8(i8* %ptr, i32 0, i32 3, i32 2)
-  call void @llvm.prefetch(i8* %ptr, i32 0, i32 3, i32 2)
+; CHECK: @llvm.prefetch.p0i8(i8* %ptr, i32 0, i32 3, i32 1)
+  call void @llvm.prefetch(i8* %ptr, i32 0, i32 3, i32 1)
   ret void
 }
 
 declare void @llvm.prefetch.p0i8(i8*, i32, i32, i32)
 define void @test.prefetch.2(i8* %ptr) {
 ; CHECK-LABEL: @test.prefetch.2(
-; CHECK: @llvm.prefetch.p0i8(i8* %ptr, i32 0, i32 3, i32 2)
-  call void @llvm.prefetch(i8* %ptr, i32 0, i32 3, i32 2)
+; CHECK: @llvm.prefetch.p0i8(i8* %ptr, i32 0, i32 3, i32 1)
+  call void @llvm.prefetch(i8* %ptr, i32 0, i32 3, i32 1)
   ret void
 }
 
 declare void @llvm.prefetch.unnamed(%0**, i32, i32, i32)
 define void @test.prefetch.unnamed(%0** %ptr) {
 ; CHECK-LABEL: @test.prefetch.unnamed(
-; CHECK: @llvm.prefetch.p0p0s_s.0(%0** %ptr, i32 0, i32 3, i32 2)
-  call void @llvm.prefetch.unnamed(%0** %ptr, i32 0, i32 3, i32 2)
+; CHECK: @llvm.prefetch.p0p0s_s.0(%0** %ptr, i32 0, i32 3, i32 1)
+  call void @llvm.prefetch.unnamed(%0** %ptr, i32 0, i32 3, i32 1)
   ret void
 }
 
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -5121,9 +5121,12 @@
           Call);
     break;
   case Intrinsic::prefetch:
-    Check(cast<ConstantInt>(Call.getArgOperand(1))->getZExtValue() < 2 &&
-              cast<ConstantInt>(Call.getArgOperand(2))->getZExtValue() < 4,
-          "invalid arguments to llvm.prefetch", Call);
+    Check(cast<ConstantInt>(Call.getArgOperand(1))->getZExtValue() < 2,
+          "rw argument to llvm.prefetch must be 0-1", Call);
+    Check(cast<ConstantInt>(Call.getArgOperand(2))->getZExtValue() < 4,
+          "locality argument to llvm.prefetch must be 0-4", Call);
+    Check(cast<ConstantInt>(Call.getArgOperand(3))->getZExtValue() < 2,
+          "cache type argument to llvm.prefetch must be 0-1", Call);
     break;
   case Intrinsic::stackprotector:
     Check(isa<AllocaInst>(Call.getArgOperand(1)->stripPointerCasts()),
Index: llvm/include/llvm/IR/Intrinsics.td
===================================================================
--- llvm/include/llvm/IR/Intrinsics.td
+++ llvm/include/llvm/IR/Intrinsics.td
@@ -567,7 +567,7 @@
     : DefaultAttrsIntrinsic<[], [ llvm_anyptr_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty ],
                 [IntrInaccessibleMemOrArgMemOnly, IntrWillReturn,
                  ReadOnly<ArgIndex<0>>, NoCapture<ArgIndex<0>>,
-                 ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>]>;
+                 ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>]>;
 def int_pcmarker      : DefaultAttrsIntrinsic<[], [llvm_i32_ty]>;
 
 def int_readcyclecounter : DefaultAttrsIntrinsic<[llvm_i64_ty]>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132042.453343.patch
Type: text/x-patch
Size: 3559 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220817/ae45beda/attachment.bin>


More information about the llvm-commits mailing list