[llvm-commits] [llvm] r80959 - in /llvm/trunk: include/llvm-c/Core.h include/llvm/Constants.h include/llvm/Support/ConstantFolder.h include/llvm/Support/NoFolder.h include/llvm/Support/TargetFolder.h lib/Analysis/ConstantFolding.cpp lib/VMCore/ConstantFold.cpp lib/VMCore/Constants.cpp lib/VMCore/Core.cpp

Dan Gohman gohman at apple.com
Thu Sep 3 15:17:41 PDT 2009


Author: djg
Date: Thu Sep  3 17:17:40 2009
New Revision: 80959

URL: http://llvm.org/viewvc/llvm-project?rev=80959&view=rev
Log:
Remove the API for creating ConstantExprs with the nsw, nuw, inbounds,
and exact flags. Because ConstantExprs are uniqued, creating an
expression with this flag causes all expressions with the same operands
to have the same flag, which may not be safe. Add, sub, mul, and sdiv
ConstantExprs are usually folded anyway, so the main interesting flag
here is inbounds, and the constant folder already knows how to set the
inbounds flag automatically in most cases, so there isn't an urgent need
for the API support.

This can be reconsidered in the future, but for now just removing these
API bits eliminates a source of potential trouble with little downside.

Modified:
    llvm/trunk/include/llvm-c/Core.h
    llvm/trunk/include/llvm/Constants.h
    llvm/trunk/include/llvm/Support/ConstantFolder.h
    llvm/trunk/include/llvm/Support/NoFolder.h
    llvm/trunk/include/llvm/Support/TargetFolder.h
    llvm/trunk/lib/Analysis/ConstantFolding.cpp
    llvm/trunk/lib/VMCore/ConstantFold.cpp
    llvm/trunk/lib/VMCore/Constants.cpp
    llvm/trunk/lib/VMCore/Core.cpp

Modified: llvm/trunk/include/llvm-c/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=80959&r1=80958&r2=80959&view=diff

==============================================================================
--- llvm/trunk/include/llvm-c/Core.h (original)
+++ llvm/trunk/include/llvm-c/Core.h Thu Sep  3 17:17:40 2009
@@ -470,7 +470,6 @@
 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
-LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
@@ -478,7 +477,6 @@
 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
-LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
@@ -495,9 +493,6 @@
 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
                           LLVMValueRef *ConstantIndices, unsigned NumIndices);
-LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
-                                  LLVMValueRef *ConstantIndices,
-                                  unsigned NumIndices);
 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);

Modified: llvm/trunk/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constants.h?rev=80959&r1=80958&r2=80959&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Constants.h (original)
+++ llvm/trunk/include/llvm/Constants.h Thu Sep  3 17:17:40 2009
@@ -648,9 +648,6 @@
   static Constant *getIntToPtr(Constant *C, const Type *Ty);
   static Constant *getBitCast (Constant *C, const Type *Ty);
 
-  static Constant* getNSWAdd(Constant* C1, Constant* C2);
-  static Constant* getExactSDiv(Constant* C1, Constant* C2);
-
   /// Transparently provide more efficient getOperand methods.
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
 
@@ -737,15 +734,6 @@
   static Constant *getGetElementPtr(Constant *C,
                                     Value* const *IdxList, unsigned NumIdx);
 
-  /// Create an "inbounds" getelementptr. See the documentation for the
-  /// "inbounds" flag in LangRef.html for details.
-  static Constant *getInBoundsGetElementPtr(Constant *C,
-                                            Constant* const *IdxList,
-                                            unsigned NumIdx);
-  static Constant *getInBoundsGetElementPtr(Constant *C,
-                                            Value* const *IdxList,
-                                            unsigned NumIdx);
-
   static Constant *getExtractElement(Constant *Vec, Constant *Idx);
   static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
   static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);

Modified: llvm/trunk/include/llvm/Support/ConstantFolder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ConstantFolder.h?rev=80959&r1=80958&r2=80959&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/ConstantFolder.h (original)
+++ llvm/trunk/include/llvm/Support/ConstantFolder.h Thu Sep  3 17:17:40 2009
@@ -36,7 +36,7 @@
     return ConstantExpr::getAdd(LHS, RHS);
   }
   Constant *CreateNSWAdd(Constant *LHS, Constant *RHS) const {
-    return ConstantExpr::getNSWAdd(LHS, RHS);
+    return ConstantExpr::getAdd(LHS, RHS);
   }
   Constant *CreateFAdd(Constant *LHS, Constant *RHS) const {
     return ConstantExpr::getFAdd(LHS, RHS);
@@ -60,7 +60,7 @@
     return ConstantExpr::getSDiv(LHS, RHS);
   }
   Constant *CreateExactSDiv(Constant *LHS, Constant *RHS) const {
-    return ConstantExpr::getExactSDiv(LHS, RHS);
+    return ConstantExpr::getSDiv(LHS, RHS);
   }
   Constant *CreateFDiv(Constant *LHS, Constant *RHS) const {
     return ConstantExpr::getFDiv(LHS, RHS);
@@ -127,11 +127,11 @@
 
   Constant *CreateInBoundsGetElementPtr(Constant *C, Constant* const *IdxList,
                                         unsigned NumIdx) const {
-    return ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx);
+    return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
   }
   Constant *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList,
                                         unsigned NumIdx) const {
-    return ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx);
+    return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
   }
 
   //===--------------------------------------------------------------------===//

Modified: llvm/trunk/include/llvm/Support/NoFolder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/NoFolder.h?rev=80959&r1=80958&r2=80959&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/NoFolder.h (original)
+++ llvm/trunk/include/llvm/Support/NoFolder.h Thu Sep  3 17:17:40 2009
@@ -131,7 +131,7 @@
 
   Constant *CreateInBoundsGetElementPtr(Constant *C, Constant* const *IdxList,
                                         unsigned NumIdx) const {
-    return ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx);
+    return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
   }
   Value *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList,
                                      unsigned NumIdx) const {

Modified: llvm/trunk/include/llvm/Support/TargetFolder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TargetFolder.h?rev=80959&r1=80958&r2=80959&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/TargetFolder.h (original)
+++ llvm/trunk/include/llvm/Support/TargetFolder.h Thu Sep  3 17:17:40 2009
@@ -52,7 +52,7 @@
     return Fold(ConstantExpr::getAdd(LHS, RHS));
   }
   Constant *CreateNSWAdd(Constant *LHS, Constant *RHS) const {
-    return Fold(ConstantExpr::getNSWAdd(LHS, RHS));
+    return Fold(ConstantExpr::getAdd(LHS, RHS));
   }
   Constant *CreateFAdd(Constant *LHS, Constant *RHS) const {
     return Fold(ConstantExpr::getFAdd(LHS, RHS));
@@ -76,7 +76,7 @@
     return Fold(ConstantExpr::getSDiv(LHS, RHS));
   }
   Constant *CreateExactSDiv(Constant *LHS, Constant *RHS) const {
-    return Fold(ConstantExpr::getExactSDiv(LHS, RHS));
+    return Fold(ConstantExpr::getSDiv(LHS, RHS));
   }
   Constant *CreateFDiv(Constant *LHS, Constant *RHS) const {
     return Fold(ConstantExpr::getFDiv(LHS, RHS));
@@ -143,11 +143,11 @@
 
   Constant *CreateInBoundsGetElementPtr(Constant *C, Constant* const *IdxList,
                                         unsigned NumIdx) const {
-    return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx));
+    return Fold(ConstantExpr::getGetElementPtr(C, IdxList, NumIdx));
   }
   Constant *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList,
                                         unsigned NumIdx) const {
-    return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx));
+    return Fold(ConstantExpr::getGetElementPtr(C, IdxList, NumIdx));
   }
 
   //===--------------------------------------------------------------------===//

Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=80959&r1=80958&r2=80959&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Thu Sep  3 17:17:40 2009
@@ -203,15 +203,21 @@
   if (Offset != 0)
     return 0;
 
+  // Create the GEP constant expr.
+  Constant *C = ConstantExpr::getGetElementPtr(Ptr,
+                                               &NewIdxs[0], NewIdxs.size());
+  assert(cast<PointerType>(C->getType())->getElementType() == Ty &&
+         "Computed GetElementPtr has unexpected type!");
+
   // If the base is the start of a GlobalVariable and all the array indices
   // remain in their static bounds, the GEP is inbounds. We can check that
   // all indices are in bounds by just checking the first index only
-  // because we've just normalized all the indices.
-  Constant *C = isa<GlobalVariable>(Ptr) && NewIdxs[0]->isNullValue() ?
-    ConstantExpr::getInBoundsGetElementPtr(Ptr, &NewIdxs[0], NewIdxs.size()) :
-    ConstantExpr::getGetElementPtr(Ptr, &NewIdxs[0], NewIdxs.size());
-  assert(cast<PointerType>(C->getType())->getElementType() == Ty &&
-         "Computed GetElementPtr has unexpected type!");
+  // because we've just normalized all the indices. We can mutate the
+  // Constant in place because we've proven that the indices are in bounds,
+  // so they'll always be in bounds.
+  if (isa<GlobalVariable>(Ptr) && NewIdxs[0]->isNullValue())
+    if (GEPOperator *GEP = dyn_cast<GEPOperator>(C))
+      GEP->setIsInBounds(true);
 
   // If we ended up indexing a member with a type that doesn't match
   // the type of what the original indices indexed, add a cast.

Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=80959&r1=80958&r2=80959&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Thu Sep  3 17:17:40 2009
@@ -122,9 +122,7 @@
         }
 
         if (ElTy == DPTy->getElementType())
-          // This GEP is inbounds because all indices are zero.
-          return ConstantExpr::getInBoundsGetElementPtr(V, &IdxList[0],
-                                                        IdxList.size());
+          return ConstantExpr::getGetElementPtr(V, &IdxList[0], IdxList.size());
       }
 
   // Handle casts from one vector constant to another.  We know that the src 

Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=80959&r1=80958&r2=80959&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Thu Sep  3 17:17:40 2009
@@ -631,24 +631,6 @@
   return get(std::vector<Constant*>(Vals, Vals+NumVals));
 }
 
-Constant* ConstantExpr::getNSWAdd(Constant* C1, Constant* C2) {
-  Constant *C = getAdd(C1, C2);
-  // Set nsw attribute, assuming constant folding didn't eliminate the
-  // Add.
-  if (AddOperator *Add = dyn_cast<AddOperator>(C))
-    Add->setHasNoSignedWrap(true);
-  return C;
-}
-
-Constant* ConstantExpr::getExactSDiv(Constant* C1, Constant* C2) {
-  Constant *C = getSDiv(C1, C2);
-  // Set exact attribute, assuming constant folding didn't eliminate the
-  // SDiv.
-  if (SDivOperator *SDiv = dyn_cast<SDivOperator>(C))
-    SDiv->setIsExact(true);
-  return C;
-}
-
 // Utility function for determining if a ConstantExpr is a CastOp or not. This
 // can't be inline because we don't want to #include Instruction.h into
 // Constant.h
@@ -1491,28 +1473,11 @@
   return getGetElementPtrTy(PointerType::get(Ty, As), C, Idxs, NumIdx);
 }
 
-Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C,
-                                                 Value* const *Idxs,
-                                                 unsigned NumIdx) {
-  Constant *Result = getGetElementPtr(C, Idxs, NumIdx);
-  // Set in bounds attribute, assuming constant folding didn't eliminate the
-  // GEP.
-  if (GEPOperator *GEP = dyn_cast<GEPOperator>(Result))
-    GEP->setIsInBounds(true);
-  return Result;
-}
-
 Constant *ConstantExpr::getGetElementPtr(Constant *C, Constant* const *Idxs,
                                          unsigned NumIdx) {
   return getGetElementPtr(C, (Value* const *)Idxs, NumIdx);
 }
 
-Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C,
-                                                 Constant* const *Idxs,
-                                                 unsigned NumIdx) {
-  return getInBoundsGetElementPtr(C, (Value* const *)Idxs, NumIdx);
-}
-
 Constant *
 ConstantExpr::getICmp(unsigned short pred, Constant* LHS, Constant* RHS) {
   assert(LHS->getType() == RHS->getType());

Modified: llvm/trunk/lib/VMCore/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=80959&r1=80958&r2=80959&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Core.cpp (original)
+++ llvm/trunk/lib/VMCore/Core.cpp Thu Sep  3 17:17:40 2009
@@ -535,13 +535,6 @@
                                    unwrap<Constant>(RHSConstant)));
 }
 
-LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant,
-                             LLVMValueRef RHSConstant) {
-  return wrap(ConstantExpr::getNSWAdd(
-                                      unwrap<Constant>(LHSConstant),
-                                      unwrap<Constant>(RHSConstant)));
-}
-
 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
   return wrap(ConstantExpr::getFAdd(
                                     unwrap<Constant>(LHSConstant),
@@ -583,13 +576,6 @@
                                     unwrap<Constant>(RHSConstant)));
 }
 
-LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant,
-                                LLVMValueRef RHSConstant) {
-  return wrap(ConstantExpr::getExactSDiv(
-                                         unwrap<Constant>(LHSConstant),
-                                         unwrap<Constant>(RHSConstant)));
-}
-
 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
   return wrap(ConstantExpr::getFDiv(
                                     unwrap<Constant>(LHSConstant),
@@ -673,14 +659,6 @@
                                              NumIndices));
 }
 
-LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
-                                  LLVMValueRef *ConstantIndices,
-                                  unsigned NumIndices) {
-  Constant* Val = unwrap<Constant>(ConstantVal);
-  Constant** Idxs = unwrap<Constant>(ConstantIndices, NumIndices);
-  return wrap(ConstantExpr::getInBoundsGetElementPtr(Val, Idxs, NumIndices));
-}
-
 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
   return wrap(ConstantExpr::getTrunc(
                                      unwrap<Constant>(ConstantVal),





More information about the llvm-commits mailing list