[cfe-commits] r68590 - in /cfe/trunk/lib/CodeGen: CGExpr.cpp CGExprScalar.cpp

Sanjiv Gupta sanjiv.gupta at microchip.com
Tue Apr 7 21:16:39 PDT 2009


Author: sgupta
Date: Tue Apr  7 23:16:39 2009
New Revision: 68590

URL: http://llvm.org/viewvc/llvm-project?rev=68590&view=rev
Log:
Pointer width on targets like PIC16 is 16-bit, while the valid index size to GEP is only 32 or 64. So promote index to 32 in such cases.

Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=68590&r1=68589&r2=68590&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Apr  7 23:16:39 2009
@@ -799,8 +799,11 @@
   QualType IdxTy  = E->getIdx()->getType();
   bool IdxSigned = IdxTy->isSignedIntegerType();
   unsigned IdxBitwidth = cast<llvm::IntegerType>(Idx->getType())->getBitWidth();
-  if (IdxBitwidth != LLVMPointerWidth)
-    Idx = Builder.CreateIntCast(Idx, llvm::IntegerType::get(LLVMPointerWidth),
+  
+  // If Pointer width is less than 32 than extend to 32.
+  unsigned IdxValidWidth = (LLVMPointerWidth < 32 ) ? 32 : LLVMPointerWidth;
+  if (IdxBitwidth != IdxValidWidth)
+    Idx = Builder.CreateIntCast(Idx, llvm::IntegerType::get(IdxValidWidth),
                                 IdxSigned, "idxprom");
 
   // We know that the pointer points to a type of the correct size, unless the

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=68590&r1=68589&r2=68590&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Apr  7 23:16:39 2009
@@ -944,10 +944,14 @@
   }
 
   unsigned Width = cast<llvm::IntegerType>(Idx->getType())->getBitWidth();
-  if (Width < CGF.LLVMPointerWidth) {
+  // Only 32 and 64 are valid index widths. So if a target has shorter 
+  // pointe width, extend to 32 at least.
+  unsigned IdxValidWidth 
+    = (CGF.LLVMPointerWidth < 32) ? 32 : CGF.LLVMPointerWidth;
+  if (Width < IdxValidWidth) {
     // Zero or sign extend the pointer value based on whether the index is
     // signed or not.
-    const llvm::Type *IdxType = llvm::IntegerType::get(CGF.LLVMPointerWidth);
+    const llvm::Type *IdxType = llvm::IntegerType::get(IdxValidWidth);
     if (IdxExp->getType()->isSignedIntegerType())
       Idx = Builder.CreateSExt(Idx, IdxType, "idx.ext");
     else
@@ -990,10 +994,12 @@
     // pointer - int
     Value *Idx = Ops.RHS;
     unsigned Width = cast<llvm::IntegerType>(Idx->getType())->getBitWidth();
-    if (Width < CGF.LLVMPointerWidth) {
+    unsigned IdxValidWidth 
+      = (CGF.LLVMPointerWidth < 32) ? 32 : CGF.LLVMPointerWidth;
+    if (Width < IdxValidWidth) {
       // Zero or sign extend the pointer value based on whether the index is
       // signed or not.
-      const llvm::Type *IdxType = llvm::IntegerType::get(CGF.LLVMPointerWidth);
+      const llvm::Type *IdxType = llvm::IntegerType::get(IdxValidWidth);
       if (Ops.E->getRHS()->getType()->isSignedIntegerType())
         Idx = Builder.CreateSExt(Idx, IdxType, "idx.ext");
       else





More information about the cfe-commits mailing list