[PATCH] D85912: [VectorCombine] Fix for non-zero addrspace when creating vector load from scalar load

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 13 08:44:46 PDT 2020


bjope created this revision.
bjope added a reviewer: spatel.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
bjope requested review of this revision.

This is a fixup to commit 43bdac290663f4424f9fb <https://reviews.llvm.org/rG43bdac290663f4424f9fb3920c47c7288a2aabb4>, to make sure the
address space from the original load pointer is retained in the
vector pointer.

Resolves problem with

  Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed.

due to address space mismatch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85912

Files:
  llvm/lib/Transforms/Vectorize/VectorCombine.cpp
  llvm/test/Transforms/VectorCombine/X86/load.ll


Index: llvm/test/Transforms/VectorCombine/X86/load.ll
===================================================================
--- llvm/test/Transforms/VectorCombine/X86/load.ll
+++ llvm/test/Transforms/VectorCombine/X86/load.ll
@@ -234,6 +234,19 @@
   ret <4 x float> %r
 }
 
+; Should work with addrspace as well.
+
+define <4 x float> @gep00_load_f32_insert_v4f32_addrspace(<4 x float> addrspace(44)* align 16 dereferenceable(16) %p) {
+; CHECK-LABEL: @gep00_load_f32_insert_v4f32_addrspace(
+; CHECK-NEXT:    [[R:%.*]] = load <4 x float>, <4 x float> addrspace(44)* [[P:%.*]], align 16
+; CHECK-NEXT:    ret <4 x float> [[R]]
+;
+  %gep = getelementptr inbounds <4 x float>, <4 x float> addrspace(44)* %p, i64 0, i64 0
+  %s = load float, float addrspace(44)* %gep, align 16
+  %r = insertelement <4 x float> undef, float %s, i64 0
+  ret <4 x float> %r
+}
+
 ; If there are enough dereferenceable bytes, we can offset the vector load.
 
 define <8 x i16> @gep01_load_i16_insert_v8i16(<8 x i16>* align 16 dereferenceable(18) %p) {
Index: llvm/lib/Transforms/Vectorize/VectorCombine.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -139,7 +139,9 @@
   // It is safe and potentially profitable to load a vector directly:
   // inselt undef, load Scalar, 0 --> load VecPtr
   IRBuilder<> Builder(Load);
-  Value *CastedPtr = Builder.CreateBitCast(PtrOp, VectorTy->getPointerTo());
+  Value *CastedPtr = Builder.CreateBitCast(PtrOp,
+                                           VectorTy->getPointerTo(
+                                               Load->getPointerAddressSpace()));
   LoadInst *VecLd = Builder.CreateAlignedLoad(VectorTy, CastedPtr, Alignment);
   replaceValue(I, *VecLd);
   ++NumVecLoad;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85912.285387.patch
Type: text/x-patch
Size: 1833 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200813/560d4a1a/attachment.bin>


More information about the llvm-commits mailing list