[llvm] 8911a35 - [SROA] convertValue(): we can have <N x iK*> to <M x iQ> cast

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 24 14:59:27 PDT 2020


Author: Roman Lebedev
Date: 2020-06-25T00:58:54+03:00
New Revision: 8911a35180c6777188fefe0954a2451a2b91deaf

URL: https://github.com/llvm/llvm-project/commit/8911a35180c6777188fefe0954a2451a2b91deaf
DIFF: https://github.com/llvm/llvm-project/commit/8911a35180c6777188fefe0954a2451a2b91deaf.diff

LOG: [SROA] convertValue(): we can have <N x iK*> to <M x iQ> cast

Provided test case crashes otherwise.
Much like to the opposite case.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/SROA.cpp
    llvm/test/Transforms/SROA/vector-conversion.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index c6227a2e9014..68c01626db2c 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -1757,20 +1757,14 @@ static Value *convertValue(const DataLayout &DL, IRBuilderTy &IRB, Value *V,
                               NewTy);
   }
 
-  // See if we need ptrtoint for this type pair. A cast involving both scalars
-  // and vectors requires and additional bitcast.
+  // See if we need ptrtoint for this type pair. May require additional bitcast.
   if (OldTy->isPtrOrPtrVectorTy() && NewTy->isIntOrIntVectorTy()) {
     // Expand <2 x i8*> to i128 --> <2 x i8*> to <2 x i64> to i128
-    if (OldTy->isVectorTy() && !NewTy->isVectorTy())
-      return IRB.CreateBitCast(IRB.CreatePtrToInt(V, DL.getIntPtrType(OldTy)),
-                               NewTy);
-
     // Expand i8* to <2 x i32> --> i8* to i64 to <2 x i32>
-    if (!OldTy->isVectorTy() && NewTy->isVectorTy())
-      return IRB.CreateBitCast(IRB.CreatePtrToInt(V, DL.getIntPtrType(OldTy)),
-                               NewTy);
-
-    return IRB.CreatePtrToInt(V, NewTy);
+    // Expand <2 x i8*> to <4 x i32> --> <2 x i8*> to <2 x i64> to <4 x i32>
+    // Expand i8* to i64 --> i8* to i64 to i64
+    return IRB.CreateBitCast(IRB.CreatePtrToInt(V, DL.getIntPtrType(OldTy)),
+                             NewTy);
   }
 
   if (OldTy->isPtrOrPtrVectorTy() && NewTy->isPtrOrPtrVectorTy()) {

diff  --git a/llvm/test/Transforms/SROA/vector-conversion.ll b/llvm/test/Transforms/SROA/vector-conversion.ll
index 79d0f12ebbe8..80d645a2e5ee 100644
--- a/llvm/test/Transforms/SROA/vector-conversion.ll
+++ b/llvm/test/Transforms/SROA/vector-conversion.ll
@@ -70,3 +70,22 @@ define <2 x i8*> @vector_inttoptrbitcast_vector({<16 x i8>, <16 x i8>} %x) {
 
   ret <2 x i8*> %vec
 }
+
+define <16 x i8> @vector_ptrtointbitcast_vector({<2 x i8*>, <2 x i8*>} %x) {
+; CHECK-LABEL: @vector_ptrtointbitcast_vector(
+  %a = alloca {<2 x i8*>, <2 x i8*>}
+; CHECK-NOT: alloca
+
+  store {<2 x i8*>, <2 x i8*>} %x, {<2 x i8*>, <2 x i8*>}* %a
+; CHECK-NOT: store
+
+  %cast = bitcast {<2 x i8*>, <2 x i8*>}* %a to <16 x i8>*
+  %vec = load <16 x i8>, <16 x i8>* %cast
+; CHECK-NOT: load
+; CHECK: extractvalue
+; CHECK: ptrtoint
+; CHECK: bitcast
+; CHECK: extractvalue
+
+  ret <16 x i8> %vec
+}


        


More information about the llvm-commits mailing list