[llvm-commits] [llvm] r90099 - in /llvm/trunk: lib/Analysis/ConstantFolding.cpp test/Transforms/InstCombine/getelementptr.ll

Nick Lewycky nicholas at mxc.ca
Sun Nov 29 13:40:55 PST 2009


Author: nicholas
Date: Sun Nov 29 15:40:55 2009
New Revision: 90099

URL: http://llvm.org/viewvc/llvm-project?rev=90099&view=rev
Log:
Teach ConstantFolding to do a better job when folding gep(bitcast).

This permits the devirtualization of llvm.org/PR3100#c9 when compiled by clang.

Modified:
    llvm/trunk/lib/Analysis/ConstantFolding.cpp
    llvm/trunk/test/Transforms/InstCombine/getelementptr.ll

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

==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Sun Nov 29 15:40:55 2009
@@ -564,6 +564,7 @@
   // 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 {

Modified: llvm/trunk/test/Transforms/InstCombine/getelementptr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/getelementptr.ll?rev=90099&r1=90098&r2=90099&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/getelementptr.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/getelementptr.ll Sun Nov 29 15:40:55 2009
@@ -445,7 +445,7 @@
              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





More information about the llvm-commits mailing list