Teach ConstantFolding to do a better job when folding gep(bitcast).
authorNick Lewycky <nicholas@mxc.ca>
Sun, 29 Nov 2009 21:40:55 +0000 (21:40 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Sun, 29 Nov 2009 21:40:55 +0000 (21:40 +0000)
This permits the devirtualization of llvm.org/PR3100#c9 when compiled by clang.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90099 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ConstantFolding.cpp
test/Transforms/InstCombine/getelementptr.ll

index 8d60907f8cb2be053eac1384bfdbc0405a73cf25..96f738edad4e8ebe54fc36d48f1b4784cc28287f 100644 (file)
@@ -564,6 +564,7 @@ static Constant *SymbolicallyEvaluateGEP(Constant *const *Ops, unsigned NumOps,
   // we eliminate over-indexing of the notional static type array bounds.
   // This makes it easy to determine if the getelementptr is "inbounds".
   // Also, this helps GlobalOpt do SROA on GlobalVariables.
+  Ptr = cast<Constant>(Ptr->stripPointerCasts());
   const Type *Ty = Ptr->getType();
   SmallVector<Constant*, 32> NewIdxs;
   do {
index 285e0ba602f42adaf1886a84c3f78cfe37067d16..de325f64021fe361129c352b3e837d781eca900b 100644 (file)
@@ -445,7 +445,7 @@ define i32 @test35() nounwind {
              i8* getelementptr (%t1* bitcast (%t0* @s to %t1*), i32 0, i32 1, i32 0)) nounwind
   ret i32 0
 ; CHECK: @test35
-; CHECK: call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([17 x i8]* @"\01LC8", i64 0, i64 0), i8* bitcast (i8** getelementptr (%t1* bitcast (%t0* @s to %t1*), i64 1, i32 0) to i8*)) nounwind
+; CHECK: call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([17 x i8]* @"\01LC8", i64 0, i64 0), i8* getelementptr inbounds (%t0* @s, i64 0, i32 1, i64 0)) nounwind
 }
 
 ; Instcombine should constant-fold the GEP so that indices that have