Teach the alignment handling code to look through constant expr casts and GEPs
authorChris Lattner <sabre@nondot.org>
Tue, 7 Mar 2006 01:28:57 +0000 (01:28 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 7 Mar 2006 01:28:57 +0000 (01:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26580 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index a3eb95025390838831c4bb82648df919817a090f..3eb452c790123b571bcbbb303feb46caeb302a2e 100644 (file)
@@ -5285,11 +5285,17 @@ static unsigned GetKnownAlignment(Value *V, TargetData *TD) {
       }
     }
     return Align;
-  } else if (CastInst *CI = dyn_cast<CastInst>(V)) {
+  } else if (isa<CastInst>(V) ||
+             (isa<ConstantExpr>(V) && 
+              cast<ConstantExpr>(V)->getOpcode() == Instruction::Cast)) {
+    User *CI = cast<User>(V);
     if (isa<PointerType>(CI->getOperand(0)->getType()))
       return GetKnownAlignment(CI->getOperand(0), TD);
     return 0;
-  } else if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(V)) {
+  } else if (isa<GetElementPtrInst>(V) ||
+             (isa<ConstantExpr>(V) && 
+              cast<ConstantExpr>(V)->getOpcode()==Instruction::GetElementPtr)) {
+    User *GEPI = cast<User>(V);
     unsigned BaseAlignment = GetKnownAlignment(GEPI->getOperand(0), TD);
     if (BaseAlignment == 0) return 0;
     
@@ -5311,8 +5317,10 @@ static unsigned GetKnownAlignment(Value *V, TargetData *TD) {
 
     const Type *BasePtrTy = GEPI->getOperand(0)->getType();
     if (TD->getTypeAlignment(cast<PointerType>(BasePtrTy)->getElementType())
-        <= BaseAlignment)
-      return TD->getTypeAlignment(GEPI->getType()->getElementType());
+        <= BaseAlignment) {
+      const Type *GEPTy = GEPI->getType();
+      return TD->getTypeAlignment(cast<PointerType>(GEPTy)->getElementType());
+    }
     return 0;
   }
   return 0;