[llvm-commits] [llvm] r164427 - in /llvm/trunk: lib/Transforms/Scalar/SROA.cpp test/Transforms/SROA/phi-and-select.ll

Chandler Carruth chandlerc at gmail.com
Fri Sep 21 16:36:40 PDT 2012


Author: chandlerc
Date: Fri Sep 21 18:36:40 2012
New Revision: 164427

URL: http://llvm.org/viewvc/llvm-project?rev=164427&view=rev
Log:
Fix a case where the new SROA pass failed to zap dead operands to
selects with a constant condition. This resulted in the operands
remaining live through the SROA rewriter. Most of the time, this just
caused some dead allocas to persist and get zapped by later passes, but
in one case found by Joerg, it caused a crash when we tried to *promote*
the alloca despite it having this dead use. We already have the
mechanisms in place to handle this, just wire select up to them.

Modified:
    llvm/trunk/lib/Transforms/Scalar/SROA.cpp
    llvm/trunk/test/Transforms/SROA/phi-and-select.ll

Modified: llvm/trunk/lib/Transforms/Scalar/SROA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=164427&r1=164426&r2=164427&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Fri Sep 21 18:36:40 2012
@@ -901,6 +901,10 @@
         // If the result of the constant fold will be the pointer, recurse
         // through the select as if we had RAUW'ed it.
         enqueueUsers(SI, Offset);
+      else
+        // Otherwise the operand to the select is dead, and we can replace it
+        // with undef.
+        P.DeadOperands.push_back(U);
 
       return;
     }

Modified: llvm/trunk/test/Transforms/SROA/phi-and-select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SROA/phi-and-select.ll?rev=164427&r1=164426&r2=164427&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SROA/phi-and-select.ll (original)
+++ llvm/trunk/test/Transforms/SROA/phi-and-select.ll Fri Sep 21 18:36:40 2012
@@ -130,31 +130,35 @@
 ; CHECK: ret i32 1
 }
 
-declare void @f(i32*)
+declare void @f(i32*, i32*)
 
 define i32 @test6(i32* %b) {
 ; CHECK: @test6
 entry:
 	%a = alloca [2 x i32]
-; The alloca remains because it is used in a dead select.
-; CHECK: alloca
+  %c = alloca i32
+; CHECK-NOT: alloca
 
   %a1 = getelementptr [2 x i32]* %a, i64 0, i32 1
 	store i32 1, i32* %a1
 
 	%select = select i1 true, i32* %a1, i32* %b
 	%select2 = select i1 false, i32* %a1, i32* %b
-; CHECK-NOT: select i1 true
-; We don't aggressively DCE this select.
-; CHECK: select i1 false
+  %select3 = select i1 false, i32* %c, i32* %b
+; CHECK: %[[select2:.*]] = select i1 false, i32* undef, i32* %b
+; CHECK: %[[select3:.*]] = select i1 false, i32* undef, i32* %b
 
   ; Note, this would potentially escape the alloca pointer except for the
   ; constant folding of the select.
-  call void @f(i32* %select2)
+  call void @f(i32* %select2, i32* %select3)
+; CHECK: call void @f(i32* %[[select2]], i32* %[[select3]])
+
 
 	%result = load i32* %select
 ; CHECK-NOT: load
 
+  %dead = load i32* %c
+
 	ret i32 %result
 ; CHECK: ret i32 1
 }





More information about the llvm-commits mailing list