[llvm-commits] [llvm] r67139 - in /llvm/trunk: lib/Transforms/IPO/DeadArgumentElimination.cpp test/Transforms/DeadArgElim/2009-03-17-MRE-Invoke.ll

Chris Lattner clattner at apple.com
Wed Mar 18 09:26:34 PDT 2009


On Mar 18, 2009, at 2:11 AM, Duncan Sands wrote:

> Hi Chris,
>
>> +        if (InvokeInst *II = dyn_cast<InvokeInst>(Call))
>> +          InsertPt = II->getNormalDest()->begin();
>
> mightn't this result in inserting the instructions before a
> phi node?

I initially thought so, but no, they aren't allowed here.  Consider  
this testcase:


define internal { i32, i32 } @foo() {
   ret {i32,i32} {i32 42, i32 4}
}

define i32 @bar2() {
   br i1 1, label %T, label %T3
T3:
   %x = invoke {i32,i32} @foo() to label %T unwind label %T2
T:
   %PN = phi i32 [0, %0], [42, %T3]
   %y = extractvalue {i32,i32} %x, 1
   ret i32 %y
T2:
   unreachable
}

This isn't accepted by the verifier because there is no way to use %x  
if it is defined on a critical edge.  If the invoke is directly used  
by a PHI, as in:

define i32 @bar2() {
   br i1 1, label %T, label %T3
T3:
   %x = invoke {i32,i32} @foo() to label %T unwind label %T2
T:
   %PN = phi {i32,i32} [zeroinitializer, %0], [%x, %T3]
   %y = extractvalue {i32,i32} %PN, 1
   ret i32 %y
T2:
   unreachable
}

Then DAE won't hack on it.

-Chris



More information about the llvm-commits mailing list