]> granicus.if.org Git - llvm/commitdiff
[Analysis] Improve EmitGEPOffset handling of vector GEPs with scalar indices.
authorCraig Topper <craig.topper@intel.com>
Tue, 27 Aug 2019 21:31:44 +0000 (21:31 +0000)
committerCraig Topper <craig.topper@intel.com>
Tue, 27 Aug 2019 21:31:44 +0000 (21:31 +0000)
This patch splats the scalar index if necessary before using it
in any integer casts or other arithmetic.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@370112 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/Utils/Local.h
test/Transforms/InstCombine/getelementptr.ll

index 23e8ab271c5566b377995178e6e061467c8dc71d..ba3513f1897712b353e4e5238df13ec059bf3282 100644 (file)
@@ -60,6 +60,10 @@ Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP,
         continue;
       }
 
+      // Splat the constant if needed.
+      if (IntPtrTy->isVectorTy() && !OpC->getType()->isVectorTy())
+        OpC = ConstantVector::getSplat(IntPtrTy->getVectorNumElements(), OpC);
+
       Constant *Scale = ConstantInt::get(IntPtrTy, Size);
       Constant *OC = ConstantExpr::getIntegerCast(OpC, IntPtrTy, true /*SExt*/);
       Scale = ConstantExpr::getMul(OC, Scale, isInBounds/*NUW*/);
@@ -67,6 +71,11 @@ Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP,
       Result = Builder->CreateAdd(Result, Scale, GEP->getName()+".offs");
       continue;
     }
+
+    // Splat the index if needed.
+    if (IntPtrTy->isVectorTy() && !Op->getType()->isVectorTy())
+      Op = Builder->CreateVectorSplat(IntPtrTy->getVectorNumElements(), Op);
+
     // Convert to correct type.
     if (Op->getType() != IntPtrTy)
       Op = Builder->CreateIntCast(Op, IntPtrTy, true, Op->getName()+".c");
index 566e15f289301aeb3dfc99b8611c683134f80573..31775e4fa561397dfdcbb439221676c07fd8634e 100644 (file)
@@ -187,6 +187,21 @@ define <2 x i1> @test13_vector(<2 x i64> %X, <2 x %S*> %P) nounwind {
   ret <2 x i1> %C
 }
 
+; This is a test of icmp + shl nuw in disguise - 4611... is 0x3fff...
+define <2 x i1> @test13_vector2(i64 %X, <2 x %S*> %P) nounwind {
+; CHECK-LABEL: @test13_vector2(
+; CHECK-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i64> undef, i64 [[X:%.*]], i32 0
+; CHECK-NEXT:    [[TMP1:%.*]] = shl nuw <2 x i64> [[DOTSPLATINSERT]], <i64 2, i64 undef>
+; CHECK-NEXT:    [[A_IDX:%.*]] = shufflevector <2 x i64> [[TMP1]], <2 x i64> undef, <2 x i32> zeroinitializer
+; CHECK-NEXT:    [[C:%.*]] = icmp eq <2 x i64> [[A_IDX]], <i64 -4, i64 -4>
+; CHECK-NEXT:    ret <2 x i1> [[C]]
+;
+  %A = getelementptr inbounds %S, <2 x %S*> %P, <2 x i64> zeroinitializer, <2 x i32> <i32 1, i32 1>, i64 %X
+  %B = getelementptr inbounds %S, <2 x %S*> %P, <2 x i64> <i64 0, i64 0>, <2 x i32> <i32 0, i32 0>
+  %C = icmp eq <2 x i32*> %A, %B
+  ret <2 x i1> %C
+}
+
 define i1 @test13_as1(i16 %X, %S addrspace(1)* %P) {
 ; CHECK-LABEL: @test13_as1(
 ; CHECK-NEXT:  %C = icmp eq i16 %X, -1