[llvm-commits] [gcc-plugin] r82858 - /gcc-plugin/trunk/llvm-convert.cpp

Duncan Sands baldrick at free.fr
Sat Sep 26 08:07:09 PDT 2009


Author: baldrick
Date: Sat Sep 26 10:07:09 2009
New Revision: 82858

URL: http://llvm.org/viewvc/llvm-project?rev=82858&view=rev
Log:
Do not generate invalid gimple when subtracting off array lower
bounds.  Instead, let LLVM do the subtraction (and hope it can
simplify such expressions as well as the GCC constant folder).
With this, the plugin can compile a bit of Ada.

Modified:
    gcc-plugin/trunk/llvm-convert.cpp

Modified: gcc-plugin/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-convert.cpp?rev=82858&r1=82857&r2=82858&view=diff

==============================================================================
--- gcc-plugin/trunk/llvm-convert.cpp (original)
+++ gcc-plugin/trunk/llvm-convert.cpp Sat Sep 26 10:07:09 2009
@@ -5785,17 +5785,16 @@
   unsigned ArrayAlign;
 
   // First subtract the lower bound, if any, in the type of the index.
+  Value *IndexVal = Emit(Index, 0);
   tree LowerBound = array_ref_low_bound(exp);
   if (!integer_zerop(LowerBound))
-    Index = fold(build2(MINUS_EXPR, IndexType, Index, LowerBound));
+    IndexVal = Builder.CreateSub(IndexVal, Emit(array_ref_low_bound(exp), 0));
 
   LValue ArrayAddrLV = EmitLV(Array);
   assert(!ArrayAddrLV.isBitfield() && "Arrays cannot be bitfields!");
   ArrayAddr = ArrayAddrLV.Ptr;
   ArrayAlign = ArrayAddrLV.getAlignment();
 
-  Value *IndexVal = Emit(Index, 0);
-
   const Type *IntPtrTy = getTargetData().getIntPtrType(Context);
   if (TYPE_UNSIGNED(IndexType)) // if the index is unsigned
     // ZExt it to retain its value in the larger type
@@ -7329,14 +7328,14 @@
          "Global with variable size?");
 
   Constant *ArrayAddr;
+
   // First subtract the lower bound, if any, in the type of the index.
+  Constant *IndexVal = Convert(Index);
   tree LowerBound = array_ref_low_bound(exp);
   if (!integer_zerop(LowerBound))
-    Index = fold(build2(MINUS_EXPR, IndexType, Index, LowerBound));
+    IndexVal = TheFolder->CreateSub(IndexVal, Convert(LowerBound));
   ArrayAddr = EmitLV(Array);
 
-  Constant *IndexVal = Convert(Index);
-
   const Type *IntPtrTy = getTargetData().getIntPtrType(Context);
   if (IndexVal->getType() != IntPtrTy)
     IndexVal = TheFolder->CreateIntCast(IndexVal, IntPtrTy,





More information about the llvm-commits mailing list