Skip to content

Commit 4bee7e0

Browse files
authored
[RISCV][IA] Rework VL for strided LD/ST optimization [nfc] (llvm#150525)
I'd originally written this creating a new VL, but realized it was probably cleaner to be explicit about the truncation which is happening. As these VLs are all constants (since these two codepaths see fixed vectors) this should result in identical constants being created.
1 parent 7c37722 commit 4bee7e0

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

llvm/lib/Target/RISCV/RISCVInterleavedAccess.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ bool RISCVTargetLowering::lowerInterleavedLoad(
224224
Value *Stride = ConstantInt::get(XLenTy, Factor * ScalarSizeInBytes);
225225
Value *Offset = ConstantInt::get(XLenTy, Indices[0] * ScalarSizeInBytes);
226226
Value *BasePtr = Builder.CreatePtrAdd(Ptr, Offset);
227-
// Note: Same VL as above, but i32 not xlen due to signature of
228-
// vp.strided.load
229-
VL = Builder.CreateElementCount(Builder.getInt32Ty(),
230-
VTy->getElementCount());
227+
// For rv64, need to truncate i64 to i32 to match signature. As VL is at most
228+
// the number of active lanes (which is bounded by i32) this is safe.
229+
VL = Builder.CreateTrunc(VL, Builder.getInt32Ty());
230+
231231
CallInst *CI =
232232
Builder.CreateIntrinsic(Intrinsic::experimental_vp_strided_load,
233233
{VTy, BasePtr->getType(), Stride->getType()},
@@ -302,10 +302,9 @@ bool RISCVTargetLowering::lowerInterleavedStore(Instruction *Store,
302302
Value *Stride = ConstantInt::get(XLenTy, Factor * ScalarSizeInBytes);
303303
Value *Offset = ConstantInt::get(XLenTy, Index * ScalarSizeInBytes);
304304
Value *BasePtr = Builder.CreatePtrAdd(Ptr, Offset);
305-
// Note: Same VL as above, but i32 not xlen due to signature of
306-
// vp.strided.store
307-
VL = Builder.CreateElementCount(Builder.getInt32Ty(),
308-
VTy->getElementCount());
305+
// For rv64, need to truncate i64 to i32 to match signature. As VL is at
306+
// most the number of active lanes (which is bounded by i32) this is safe.
307+
VL = Builder.CreateTrunc(VL, Builder.getInt32Ty());
309308

310309
CallInst *CI =
311310
Builder.CreateIntrinsic(Intrinsic::experimental_vp_strided_store,

0 commit comments

Comments
 (0)