[llvm] r233131 - Opaque Pointer Types: GEP API migrations to specify the gep type explicitly

David Blaikie dblaikie at gmail.com
Tue Mar 24 16:34:31 PDT 2015


Author: dblaikie
Date: Tue Mar 24 18:34:31 2015
New Revision: 233131

URL: http://llvm.org/viewvc/llvm-project?rev=233131&view=rev
Log:
Opaque Pointer Types: GEP API migrations to specify the gep type explicitly

The changes to InstCombine (& SCEV) do seem a bit silly - it doesn't make
anything obviously better to have the caller access the pointers element
type (the thing I'm trying to remove) than the GEP itself, but it's a
helpful migration step. This will allow me to more obviously lock down
GEP (& Load, etc) API usage, then fix all the code that accesses pointer
element types except the places that need to be removed (most of the
InstCombines) anyway - at which point I'll need to just remove all that
code because it won't be meaningful anymore (there will be no pointer
types, so no bitcasts to combine)

SCEV looks like it'll need some restructuring - we'll have to do a bit
more work for GEP canonicalization, since it'll depend on how it's used
if we can even manage to canonicalize it to a non-ugly GEP. I guess we
can do some fun stuff like voting (do 2 out of 3 load from the GEP with
a certain type that gives a pretty GEP? Does every typed use of the GEP
use either a specific type or a generic type (i8*, etc)?)

Modified:
    llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
    llvm/trunk/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
    llvm/trunk/lib/Target/R600/AMDGPUPromoteAlloca.cpp
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
    llvm/trunk/unittests/Linker/LinkModulesTest.cpp

Modified: llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp?rev=233131&r1=233130&r2=233131&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp Tue Mar 24 18:34:31 2015
@@ -374,7 +374,8 @@ Value *SCEVExpander::expandAddToGEP(cons
                                     PointerType *PTy,
                                     Type *Ty,
                                     Value *V) {
-  Type *ElTy = PTy->getElementType();
+  Type *OriginalElTy = PTy->getElementType();
+  Type *ElTy = OriginalElTy;
   SmallVector<Value *, 4> GepIndices;
   SmallVector<const SCEV *, 8> Ops(op_begin, op_end);
   bool AnyNonZeroIndices = false;
@@ -558,7 +559,7 @@ Value *SCEVExpander::expandAddToGEP(cons
   Value *Casted = V;
   if (V->getType() != PTy)
     Casted = InsertNoopCastOfTo(Casted, PTy);
-  Value *GEP = Builder.CreateGEP(Casted,
+  Value *GEP = Builder.CreateGEP(OriginalElTy, Casted,
                                  GepIndices,
                                  "scevgep");
   Ops.push_back(SE.getUnknown(GEP));

Modified: llvm/trunk/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp?rev=233131&r1=233130&r2=233131&view=diff
==============================================================================
--- llvm/trunk/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp (original)
+++ llvm/trunk/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp Tue Mar 24 18:34:31 2015
@@ -343,6 +343,7 @@ Value *GenericToNVVM::remapConstantExpr(
     // GetElementPtrConstantExpr
     return cast<GEPOperator>(C)->isInBounds()
                ? Builder.CreateGEP(
+                     cast<GEPOperator>(C)->getSourceElementType(),
                      NewOperands[0],
                      makeArrayRef(&NewOperands[1], NumOperands - 1))
                : Builder.CreateInBoundsGEP(

Modified: llvm/trunk/lib/Target/R600/AMDGPUPromoteAlloca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/R600/AMDGPUPromoteAlloca.cpp?rev=233131&r1=233130&r2=233131&view=diff
==============================================================================
--- llvm/trunk/lib/Target/R600/AMDGPUPromoteAlloca.cpp (original)
+++ llvm/trunk/lib/Target/R600/AMDGPUPromoteAlloca.cpp Tue Mar 24 18:34:31 2015
@@ -295,9 +295,9 @@ void AMDGPUPromoteAlloca::visitAlloca(Al
   DEBUG(dbgs() << "Promoting alloca to local memory\n");
   LocalMemAvailable -= AllocaSize;
 
+  Type *GVTy = ArrayType::get(I.getAllocatedType(), 256);
   GlobalVariable *GV = new GlobalVariable(
-      *Mod, ArrayType::get(I.getAllocatedType(), 256), false,
-      GlobalValue::ExternalLinkage, 0, I.getName(), 0,
+      *Mod, GVTy, false, GlobalValue::ExternalLinkage, 0, I.getName(), 0,
       GlobalVariable::NotThreadLocal, AMDGPUAS::LOCAL_ADDRESS);
 
   FunctionType *FTy = FunctionType::get(
@@ -333,7 +333,7 @@ void AMDGPUPromoteAlloca::visitAlloca(Al
   Indices.push_back(Constant::getNullValue(Type::getInt32Ty(Mod->getContext())));
   Indices.push_back(TID);
 
-  Value *Offset = Builder.CreateGEP(GV, Indices);
+  Value *Offset = Builder.CreateGEP(GVTy, GV, Indices);
   I.mutateType(Offset->getType());
   I.replaceAllUsesWith(Offset);
   I.eraseFromParent();

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=233131&r1=233130&r2=233131&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp Tue Mar 24 18:34:31 2015
@@ -1473,9 +1473,11 @@ Instruction *InstCombiner::commonPointer
         // If we were able to index down into an element, create the GEP
         // and bitcast the result.  This eliminates one bitcast, potentially
         // two.
-        Value *NGEP = cast<GEPOperator>(GEP)->isInBounds() ?
-          Builder->CreateInBoundsGEP(OrigBase, NewIndices) :
-          Builder->CreateGEP(OrigBase, NewIndices);
+        Value *NGEP = cast<GEPOperator>(GEP)->isInBounds()
+                          ? Builder->CreateInBoundsGEP(OrigBase, NewIndices)
+                          : Builder->CreateGEP(
+                                OrigBase->getType()->getPointerElementType(),
+                                OrigBase, NewIndices);
         NGEP->takeName(GEP);
 
         if (isa<BitCastInst>(CI))

Modified: llvm/trunk/unittests/Linker/LinkModulesTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Linker/LinkModulesTest.cpp?rev=233131&r1=233130&r2=233131&view=diff
==============================================================================
--- llvm/trunk/unittests/Linker/LinkModulesTest.cpp (original)
+++ llvm/trunk/unittests/Linker/LinkModulesTest.cpp Tue Mar 24 18:34:31 2015
@@ -35,7 +35,7 @@ protected:
     SwitchCase2BB = BasicBlock::Create(Ctx, "switch.case.2", F);
     ExitBB = BasicBlock::Create(Ctx, "exit", F);
 
-    ArrayType *AT = ArrayType::get(Type::getInt8PtrTy(Ctx), 3);
+    AT = ArrayType::get(Type::getInt8PtrTy(Ctx), 3);
 
     GV = new GlobalVariable(*M.get(), AT, false /*=isConstant*/,
                             GlobalValue::InternalLinkage, nullptr,"switch.bas");
@@ -61,6 +61,7 @@ protected:
   LLVMContext Ctx;
   std::unique_ptr<Module> M;
   Function *F;
+  ArrayType *AT;
   GlobalVariable *GV;
   BasicBlock *EntryBB;
   BasicBlock *SwitchCase1BB;
@@ -75,7 +76,7 @@ TEST_F(LinkModuleTest, BlockAddress) {
   GEPIndices.push_back(ConstantInt::get(Type::getInt32Ty(Ctx), 0));
   GEPIndices.push_back(F->arg_begin());
 
-  Value *GEP = Builder.CreateGEP(GV, GEPIndices, "switch.gep");
+  Value *GEP = Builder.CreateGEP(AT, GV, GEPIndices, "switch.gep");
   Value *Load = Builder.CreateLoad(GEP, "switch.load");
 
   Builder.CreateRet(Load);





More information about the llvm-commits mailing list