[PATCH] D126461: [RISCV] Extract and store new vl of vleff iff destination isn't null

Wang Pengcheng via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 26 05:53:00 PDT 2022


pcwang-thead created this revision.
pcwang-thead added reviewers: khchen, kito-cheng, craig.topper, asb.
Herald added subscribers: sunshaoce, VincentWu, luke957, StephenFan, vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson.
Herald added a project: All.
pcwang-thead requested review of this revision.
Herald added subscribers: cfe-commits, eopXD, MaskRay.
Herald added a project: clang.

Store to null will be changed to unreachable, so all instructions
after vleff intrinsic call will be deleted and it causes runtime
errors. If destination to store is null, we won't extract and store
the new vl.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126461

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics/vleff.c


Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vleff.c
===================================================================
--- clang/test/CodeGen/RISCV/rvv-intrinsics/vleff.c
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vleff.c
@@ -6,6 +6,17 @@
 
 #include <riscv_vector.h>
 
+// CHECK-RV64-LABEL: @test_vleff_save_new_vl_to_nullptr(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:    [[TMP0:%.*]] = bitcast i8* [[BASE:%.*]] to <vscale x 1 x i8>*
+// CHECK-RV64-NEXT:    [[TMP1:%.*]] = call { <vscale x 1 x i8>, i64 } @llvm.riscv.vleff.nxv1i8.i64(<vscale x 1 x i8> undef, <vscale x 1 x i8>* [[TMP0]], i64 [[VL:%.*]])
+// CHECK-RV64-NEXT:    [[TMP2:%.*]] = extractvalue { <vscale x 1 x i8>, i64 } [[TMP1]], 0
+// CHECK-RV64-NEXT:    ret <vscale x 1 x i8> [[TMP2]]
+//
+vint8mf8_t test_vleff_save_new_vl_to_nullptr (const int8_t *base, size_t vl) {
+  return vle8ff_v_i8mf8(base, NULL, vl);
+}
+
 // CHECK-RV64-LABEL: @test_vle8ff_v_i8mf8(
 // CHECK-RV64-NEXT:  entry:
 // CHECK-RV64-NEXT:    [[TMP0:%.*]] = bitcast i8* [[BASE:%.*]] to <vscale x 1 x i8>*
Index: clang/include/clang/Basic/riscv_vector.td
===================================================================
--- clang/include/clang/Basic/riscv_vector.td
+++ clang/include/clang/Basic/riscv_vector.td
@@ -643,10 +643,12 @@
         llvm::Value *LoadValue = Builder.CreateCall(F, Ops, "");
         llvm::Value *V = Builder.CreateExtractValue(LoadValue, {0});
         // Store new_vl.
-        clang::CharUnits Align =
-            CGM.getNaturalPointeeTypeAlignment(E->getArg(1)->getType());
-        llvm::Value *Val = Builder.CreateExtractValue(LoadValue, {1});
-        Builder.CreateStore(Val, Address(NewVL, Val->getType(), Align));
+        if (!isa<ConstantPointerNull>(NewVL)) {
+          clang::CharUnits Align =
+              CGM.getNaturalPointeeTypeAlignment(E->getArg(1)->getType());
+          llvm::Value *Val = Builder.CreateExtractValue(LoadValue, {1});
+          Builder.CreateStore(Val, Address(NewVL, Val->getType(), Align));
+        }
         return V;
       }
       }],
@@ -663,10 +665,12 @@
         llvm::Value *LoadValue = Builder.CreateCall(F, Ops, "");
         llvm::Value *V = Builder.CreateExtractValue(LoadValue, {0});
         // Store new_vl.
-        clang::CharUnits Align =
-            CGM.getNaturalPointeeTypeAlignment(E->getArg(3)->getType());
-        llvm::Value *Val = Builder.CreateExtractValue(LoadValue, {1});
-        Builder.CreateStore(Val, Address(NewVL, Val->getType(), Align));
+        if (!isa<ConstantPointerNull>(NewVL)) {
+          clang::CharUnits Align =
+              CGM.getNaturalPointeeTypeAlignment(E->getArg(3)->getType());
+          llvm::Value *Val = Builder.CreateExtractValue(LoadValue, {1});
+          Builder.CreateStore(Val, Address(NewVL, Val->getType(), Align));
+        }
         return V;
       }
       }] in {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126461.432257.patch
Type: text/x-patch
Size: 2865 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220526/b33415ce/attachment.bin>


More information about the cfe-commits mailing list