[llvm-commits] [llvm] r123526 - in /llvm/trunk: lib/Transforms/Scalar/CodeGenPrepare.cpp test/Transforms/CodeGenPrepare/basic.ll

Chris Lattner sabre at nondot.org
Fri Jan 14 23:36:13 PST 2011


Author: lattner
Date: Sat Jan 15 01:36:13 2011
New Revision: 123526

URL: http://llvm.org/viewvc/llvm-project?rev=123526&view=rev
Log:
fix rdar://8785296 - -fcatch-undefined-behavior generates inefficient code

The basic issue is that isel (very reasonably!) expects conditional branches
to be folded, so CGP leaving around a bunch dead computation feeding
conditional branches isn't such a good idea.  Just fold branches on constants
into unconditional branches.

Modified:
    llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
    llvm/trunk/test/Transforms/CodeGenPrepare/basic.ll

Modified: llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp?rev=123526&r1=123525&r2=123526&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp Sat Jan 15 01:36:13 2011
@@ -1071,6 +1071,9 @@
   if (CallInst *CI = dyn_cast<CallInst>(I))
     return OptimizeCallInst(CI);
 
+  if (isa<TerminatorInst>(I))
+    return ConstantFoldTerminator(I->getParent());
+  
   return false;
 }
 

Modified: llvm/trunk/test/Transforms/CodeGenPrepare/basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CodeGenPrepare/basic.ll?rev=123526&r1=123525&r2=123526&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/CodeGenPrepare/basic.ll (original)
+++ llvm/trunk/test/Transforms/CodeGenPrepare/basic.ll Sat Jan 15 01:36:13 2011
@@ -4,13 +4,16 @@
 target triple = "x86_64-apple-darwin10.0.0"
 
 ; CHECK: @test1
+; objectsize should fold to a constant, which causes the branch to fold to an
+; uncond branch.
+; rdar://8785296
 define i32 @test1(i8* %ptr) nounwind ssp noredzone align 2 {
 entry:
   %0 = tail call i64 @llvm.objectsize.i64(i8* %ptr, i1 false)
   %1 = icmp ugt i64 %0, 3
   br i1 %1, label %T, label %trap
 
-; CHECK: br i1 true, label
+; CHECK: br label %T
 trap:                                             ; preds = %0, %entry
   tail call void @llvm.trap() noreturn nounwind
   unreachable





More information about the llvm-commits mailing list