[llvm] 07a23c0 - [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:25 PDT 2020


Author: Roman Lebedev
Date: 2020-06-25T00:58:53+03:00
New Revision: 07a23c06dd9c616fc24410f8cdbc8b4797b31cdc

URL: https://github.com/llvm/llvm-project/commit/07a23c06dd9c616fc24410f8cdbc8b4797b31cdc
DIFF: https://github.com/llvm/llvm-project/commit/07a23c06dd9c616fc24410f8cdbc8b4797b31cdc.diff

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

Provided test case crashes otherwise.

If NewTy is already DL.getIntPtrType(NewTy),
CreateBitCast() won't actually create any bitcast,
so we are better off just doing the general thing.

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 b28df00e9e25..c6227a2e9014 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -1747,20 +1747,14 @@ static Value *convertValue(const DataLayout &DL, IRBuilderTy &IRB, Value *V,
   assert(!(isa<IntegerType>(OldTy) && isa<IntegerType>(NewTy)) &&
          "Integer types must be the exact same to convert.");
 
-  // See if we need inttoptr for this type pair. A cast involving both scalars
-  // and vectors requires and additional bitcast.
+  // See if we need inttoptr for this type pair. May require additional bitcast.
   if (OldTy->isIntOrIntVectorTy() && NewTy->isPtrOrPtrVectorTy()) {
     // Expand <2 x i32> to i8* --> <2 x i32> to i64 to i8*
-    if (OldTy->isVectorTy() && !NewTy->isVectorTy())
-      return IRB.CreateIntToPtr(IRB.CreateBitCast(V, DL.getIntPtrType(NewTy)),
-                                NewTy);
-
     // Expand i128 to <2 x i8*> --> i128 to <2 x i64> to <2 x i8*>
-    if (!OldTy->isVectorTy() && NewTy->isVectorTy())
-      return IRB.CreateIntToPtr(IRB.CreateBitCast(V, DL.getIntPtrType(NewTy)),
-                                NewTy);
-
-    return IRB.CreateIntToPtr(V, NewTy);
+    // Expand <4 x i32> to <2 x i8*> --> <4 x i32> to <2 x i64> to <2 x i8*>
+    // Directly handle i64 to i8*
+    return IRB.CreateIntToPtr(IRB.CreateBitCast(V, DL.getIntPtrType(NewTy)),
+                              NewTy);
   }
 
   // See if we need ptrtoint for this type pair. A cast involving both scalars

diff  --git a/llvm/test/Transforms/SROA/vector-conversion.ll b/llvm/test/Transforms/SROA/vector-conversion.ll
index 91ae5be6c3d2..79d0f12ebbe8 100644
--- a/llvm/test/Transforms/SROA/vector-conversion.ll
+++ b/llvm/test/Transforms/SROA/vector-conversion.ll
@@ -34,7 +34,7 @@ define <4 x i32*> @vector_inttoptr({<2 x i64>, <2 x i64>} %x) {
 }
 
 define <2 x i64> @vector_ptrtointbitcast({<1 x i32*>, <1 x i32*>} %x) {
-; CHECK-LABEL: @vector_ptrtointbitcast
+; CHECK-LABEL: @vector_ptrtointbitcast(
   %a = alloca {<1 x i32*>, <1 x i32*>}
 ; CHECK-NOT: alloca
 
@@ -51,3 +51,22 @@ define <2 x i64> @vector_ptrtointbitcast({<1 x i32*>, <1 x i32*>} %x) {
 
   ret <2 x i64> %vec
 }
+
+define <2 x i8*> @vector_inttoptrbitcast_vector({<16 x i8>, <16 x i8>} %x) {
+; CHECK-LABEL: @vector_inttoptrbitcast_vector(
+  %a = alloca {<16 x i8>, <16 x i8>}
+; CHECK-NOT: alloca
+
+  store {<16 x i8>, <16 x i8>} %x, {<16 x i8>, <16 x i8>}* %a
+; CHECK-NOT: store
+
+  %cast = bitcast {<16 x i8>, <16 x i8>}* %a to <2 x i8*>*
+  %vec = load <2 x i8*>, <2 x i8*>* %cast
+; CHECK-NOT: load
+; CHECK: extractvalue
+; CHECK: extractvalue
+; CHECK: bitcast
+; CHECK: inttoptr
+
+  ret <2 x i8*> %vec
+}


        


More information about the llvm-commits mailing list