[llvm-commits] [llvm] r119970 - in /llvm/trunk/lib: Analysis/InstructionSimplify.cpp Transforms/InstCombine/InstructionCombining.cpp

Duncan Sands baldrick at free.fr
Mon Nov 22 05:42:49 PST 2010


Author: baldrick
Date: Mon Nov 22 07:42:49 2010
New Revision: 119970

URL: http://llvm.org/viewvc/llvm-project?rev=119970&view=rev
Log:
Move the "gep undef" -> "undef" transform from instcombine to
InstructionSimplify.

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=119970&r1=119969&r2=119970&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Mon Nov 22 07:42:49 2010
@@ -691,13 +691,20 @@
 /// fold the result.  If not, this returns null.
 Value *llvm::SimplifyGEPInst(Value *const *Ops, unsigned NumOps,
                              const TargetData *TD, const DominatorTree *) {
+  // The type of the GEP pointer operand.
+  const PointerType *PtrTy = cast<PointerType>(Ops[0]->getType());
+
   // getelementptr P -> P.
   if (NumOps == 1)
     return Ops[0];
 
-  // TODO.
-  //if (isa<UndefValue>(Ops[0]))
-  //  return UndefValue::get(GEP.getType());
+  if (isa<UndefValue>(Ops[0])) {
+    // Compute the (pointer) type returned by the GEP instruction.
+    const Type *LastType = GetElementPtrInst::getIndexedType(PtrTy, &Ops[1],
+                                                             NumOps-1);
+    const Type *GEPTy = PointerType::get(LastType, PtrTy->getAddressSpace());
+    return UndefValue::get(GEPTy);
+  }
 
   if (NumOps == 2) {
     // getelementptr P, 0 -> P.
@@ -706,7 +713,7 @@
         return Ops[0];
     // getelementptr P, N -> P if P points to a type of zero size.
     if (TD) {
-      const Type *Ty = cast<PointerType>(Ops[0]->getType())->getElementType();
+      const Type *Ty = PtrTy->getElementType();
       if (Ty->isSized() && !TD->getTypeAllocSize(Ty))
         return Ops[0];
     }

Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=119970&r1=119969&r2=119970&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Mon Nov 22 07:42:49 2010
@@ -523,9 +523,6 @@
 
   Value *PtrOp = GEP.getOperand(0);
 
-  if (isa<UndefValue>(GEP.getOperand(0)))
-    return ReplaceInstUsesWith(GEP, UndefValue::get(GEP.getType()));
-
   // Eliminate unneeded casts for indices.
   if (TD) {
     bool MadeChange = false;





More information about the llvm-commits mailing list