[llvm] r370112 - [Analysis] Improve EmitGEPOffset handling of vector GEPs with scalar indices.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 27 14:31:45 PDT 2019


Author: ctopper
Date: Tue Aug 27 14:31:44 2019
New Revision: 370112

URL: http://llvm.org/viewvc/llvm-project?rev=370112&view=rev
Log:
[Analysis] Improve EmitGEPOffset handling of vector GEPs with scalar indices.

This patch splats the scalar index if necessary before using it
in any integer casts or other arithmetic.

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

Modified: llvm/trunk/include/llvm/Analysis/Utils/Local.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/Utils/Local.h?rev=370112&r1=370111&r2=370112&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/Utils/Local.h (original)
+++ llvm/trunk/include/llvm/Analysis/Utils/Local.h Tue Aug 27 14:31:44 2019
@@ -60,6 +60,10 @@ Value *EmitGEPOffset(IRBuilderTy *Builde
         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 *Builde
       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");

Modified: llvm/trunk/test/Transforms/InstCombine/getelementptr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/getelementptr.ll?rev=370112&r1=370111&r2=370112&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/getelementptr.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/getelementptr.ll Tue Aug 27 14:31:44 2019
@@ -187,6 +187,21 @@ define <2 x i1> @test13_vector(<2 x i64>
   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




More information about the llvm-commits mailing list