[llvm] r216582 - Revert r216439 (and r216441, else the former doesn't revert cleanly).

Nico Weber nicolasweber at gmx.de
Wed Aug 27 13:00:13 PDT 2014


Author: nico
Date: Wed Aug 27 15:00:13 2014
New Revision: 216582

URL: http://llvm.org/viewvc/llvm-project?rev=216582&view=rev
Log:
Revert r216439 (and r216441, else the former doesn't revert cleanly).

It caused PR 20771. I'll land a test on the clang side.

Removed:
    llvm/trunk/test/Transforms/InstSimplify/gep.ll
Modified:
    llvm/trunk/include/llvm/IR/PatternMatch.h
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp

Modified: llvm/trunk/include/llvm/IR/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/PatternMatch.h?rev=216582&r1=216581&r2=216582&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/IR/PatternMatch.h Wed Aug 27 15:00:13 2014
@@ -362,29 +362,6 @@ struct bind_const_intval_ty {
   }
 };
 
-/// Match a specified integer value or vector of all elements of that value.
-struct specific_intval {
-  uint64_t Val;
-  specific_intval(uint64_t V) : Val(V) {}
-
-  template<typename ITy>
-  bool match(ITy *V) {
-    ConstantInt *CI = dyn_cast<ConstantInt>(V);
-    if (!CI && V->getType()->isVectorTy())
-      if (const auto *C = dyn_cast<Constant>(V))
-        CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue());
-
-    if (CI && CI->getBitWidth() <= 64)
-      return CI->getZExtValue() == Val;
-
-    return false;
-  }
-};
-
-/// Match a specific integer value or vector with all elements equal to the
-/// value.
-inline specific_intval m_SpecificInt(uint64_t V) { return specific_intval(V); }
-
 /// m_ConstantInt - Match a ConstantInt and bind to its value.  This does not
 /// match ConstantInts wider than 64-bits.
 inline bind_const_intval_ty m_ConstantInt(uint64_t &V) { return V; }

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=216582&r1=216581&r2=216582&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Wed Aug 27 15:00:13 2014
@@ -2799,71 +2799,29 @@ Value *llvm::SimplifySelectInst(Value *C
 static Value *SimplifyGEPInst(ArrayRef<Value *> Ops, const Query &Q, unsigned) {
   // The type of the GEP pointer operand.
   PointerType *PtrTy = cast<PointerType>(Ops[0]->getType()->getScalarType());
-  unsigned AS = PtrTy->getAddressSpace();
 
   // getelementptr P -> P.
   if (Ops.size() == 1)
     return Ops[0];
 
-  // Compute the (pointer) type returned by the GEP instruction.
-  Type *LastType = GetElementPtrInst::getIndexedType(PtrTy, Ops.slice(1));
-  Type *GEPTy = PointerType::get(LastType, AS);
-  if (VectorType *VT = dyn_cast<VectorType>(Ops[0]->getType()))
-    GEPTy = VectorType::get(GEPTy, VT->getNumElements());
-
-  if (isa<UndefValue>(Ops[0]))
+  if (isa<UndefValue>(Ops[0])) {
+    // Compute the (pointer) type returned by the GEP instruction.
+    Type *LastType = GetElementPtrInst::getIndexedType(PtrTy, Ops.slice(1));
+    Type *GEPTy = PointerType::get(LastType, PtrTy->getAddressSpace());
+    if (VectorType *VT = dyn_cast<VectorType>(Ops[0]->getType()))
+      GEPTy = VectorType::get(GEPTy, VT->getNumElements());
     return UndefValue::get(GEPTy);
+  }
 
   if (Ops.size() == 2) {
     // getelementptr P, 0 -> P.
     if (match(Ops[1], m_Zero()))
       return Ops[0];
-
-    Type *Ty = PtrTy->getElementType();
-    if (Q.DL && Ty->isSized()) {
-      Value *P;
-      uint64_t C;
-      uint64_t TyAllocSize = Q.DL->getTypeAllocSize(Ty);
-      // getelementptr P, N -> P if P points to a type of zero size.
-      if (TyAllocSize == 0)
+    // getelementptr P, N -> P if P points to a type of zero size.
+    if (Q.DL) {
+      Type *Ty = PtrTy->getElementType();
+      if (Ty->isSized() && Q.DL->getTypeAllocSize(Ty) == 0)
         return Ops[0];
-
-      // The following transforms are only safe if the ptrtoint cast
-      // doesn't truncate the pointers.
-      if (Ops[1]->getType()->getScalarSizeInBits() ==
-          Q.DL->getPointerSizeInBits(AS)) {
-        auto PtrToIntOrZero = [GEPTy](Value *P) -> Value * {
-          if (match(P, m_Zero()))
-            return Constant::getNullValue(GEPTy);
-          Value *Temp;
-          if (match(P, m_PtrToInt(m_Value(Temp))))
-            return Temp;
-          return nullptr;
-        };
-
-        // getelementptr V, (sub P, V) -> P if P points to a type of size 1.
-        if (TyAllocSize == 1 &&
-            match(Ops[1], m_Sub(m_Value(P), m_PtrToInt(m_Specific(Ops[0])))))
-          if (Value *R = PtrToIntOrZero(P))
-            return R;
-
-        // getelementptr V, (ashr (sub P, V), C) -> Q
-        // if P points to a type of size 1 << C.
-        if (match(Ops[1],
-                  m_AShr(m_Sub(m_Value(P), m_PtrToInt(m_Specific(Ops[0]))),
-                         m_ConstantInt(C))) &&
-            TyAllocSize == 1ULL << C)
-          if (Value *R = PtrToIntOrZero(P))
-            return R;
-
-        // getelementptr V, (sdiv (sub P, V), C) -> Q
-        // if P points to a type of size C.
-        if (match(Ops[1],
-                  m_SDiv(m_Sub(m_Value(P), m_PtrToInt(m_Specific(Ops[0]))),
-                         m_SpecificInt(TyAllocSize))))
-          if (Value *R = PtrToIntOrZero(P))
-            return R;
-      }
     }
   }
 

Removed: llvm/trunk/test/Transforms/InstSimplify/gep.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/gep.ll?rev=216581&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/gep.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/gep.ll (removed)
@@ -1,66 +0,0 @@
-; RUN: opt -S -instsimplify < %s | FileCheck %s
-
-target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
-
-%struct.A = type { [7 x i8] }
-
-define %struct.A* @test1(%struct.A* %b, %struct.A* %e) {
-  %e_ptr = ptrtoint %struct.A* %e to i64
-  %b_ptr = ptrtoint %struct.A* %b to i64
-  %sub = sub i64 %e_ptr, %b_ptr
-  %sdiv = sdiv exact i64 %sub, 7
-  %gep = getelementptr inbounds %struct.A* %b, i64 %sdiv
-  ret %struct.A* %gep
-; CHECK-LABEL: @test1
-; CHECK-NEXT: ret %struct.A* %e
-}
-
-define i8* @test2(i8* %b, i8* %e) {
-  %e_ptr = ptrtoint i8* %e to i64
-  %b_ptr = ptrtoint i8* %b to i64
-  %sub = sub i64 %e_ptr, %b_ptr
-  %gep = getelementptr inbounds i8* %b, i64 %sub
-  ret i8* %gep
-; CHECK-LABEL: @test2
-; CHECK-NEXT: ret i8* %e
-}
-
-define i64* @test3(i64* %b, i64* %e) {
-  %e_ptr = ptrtoint i64* %e to i64
-  %b_ptr = ptrtoint i64* %b to i64
-  %sub = sub i64 %e_ptr, %b_ptr
-  %ashr = ashr exact i64 %sub, 3
-  %gep = getelementptr inbounds i64* %b, i64 %ashr
-  ret i64* %gep
-; CHECK-LABEL: @test3
-; CHECK-NEXT: ret i64* %e
-}
-
-define %struct.A* @test4(%struct.A* %b) {
-  %b_ptr = ptrtoint %struct.A* %b to i64
-  %sub = sub i64 0, %b_ptr
-  %sdiv = sdiv exact i64 %sub, 7
-  %gep = getelementptr inbounds %struct.A* %b, i64 %sdiv
-  ret %struct.A* %gep
-; CHECK-LABEL: @test4
-; CHECK-NEXT: ret %struct.A* null
-}
-
-define i8* @test5(i8* %b) {
-  %b_ptr = ptrtoint i8* %b to i64
-  %sub = sub i64 0, %b_ptr
-  %gep = getelementptr inbounds i8* %b, i64 %sub
-  ret i8* %gep
-; CHECK-LABEL: @test5
-; CHECK-NEXT: ret i8* null
-}
-
-define i64* @test6(i64* %b) {
-  %b_ptr = ptrtoint i64* %b to i64
-  %sub = sub i64 0, %b_ptr
-  %ashr = ashr exact i64 %sub, 3
-  %gep = getelementptr inbounds i64* %b, i64 %ashr
-  ret i64* %gep
-; CHECK-LABEL: @test6
-; CHECK-NEXT: ret i64* null
-}





More information about the llvm-commits mailing list