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

Chris Lattner sabre at nondot.org
Tue Mar 17 17:31:45 PDT 2009


Author: lattner
Date: Tue Mar 17 19:31:45 2009
New Revision: 67139

URL: http://llvm.org/viewvc/llvm-project?rev=67139&view=rev
Log:
Fix PR3807 by inserting 'insertelement' instructions in the normal dest of 
an invoke instead of after the invoke (in its block), which is invalid.

Added:
    llvm/trunk/test/Transforms/DeadArgElim/2009-03-17-MRE-Invoke.ll
Modified:
    llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp

Modified: llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp?rev=67139&r1=67138&r2=67139&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp Tue Mar 17 19:31:45 2009
@@ -798,9 +798,13 @@
         // Replace by null for now.
         Call->replaceAllUsesWith(Constant::getNullValue(Call->getType()));
       } else {
-        assert(isa<StructType>(RetTy) && "Return type changed, but not into a"
-                                         "void. The old return type must have"
-                                         "been a struct!");
+        assert(isa<StructType>(RetTy) &&
+               "Return type changed, but not into a void. The old return type"
+               " must have been a struct!");
+        Instruction *InsertPt = Call;
+        if (InvokeInst *II = dyn_cast<InvokeInst>(Call))
+          InsertPt = II->getNormalDest()->begin();
+          
         // We used to return a struct. Instead of doing smart stuff with all the
         // uses of this struct, we will just rebuild it using
         // extract/insertvalue chaining and let instcombine clean that up.
@@ -813,12 +817,13 @@
             if (RetTypes.size() > 1)
               // We are still returning a struct, so extract the value from our
               // return value
-              V = ExtractValueInst::Create(New, NewRetIdxs[i], "newret", Call);
+              V = ExtractValueInst::Create(New, NewRetIdxs[i], "newret",
+                                           InsertPt);
             else
               // We are now returning a single element, so just insert that
               V = New;
             // Insert the value at the old position
-            RetVal = InsertValueInst::Create(RetVal, V, i, "oldret", Call);
+            RetVal = InsertValueInst::Create(RetVal, V, i, "oldret", InsertPt);
           }
         // Now, replace all uses of the old call instruction with the return
         // struct we built

Added: llvm/trunk/test/Transforms/DeadArgElim/2009-03-17-MRE-Invoke.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/DeadArgElim/2009-03-17-MRE-Invoke.ll?rev=67139&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/DeadArgElim/2009-03-17-MRE-Invoke.ll (added)
+++ llvm/trunk/test/Transforms/DeadArgElim/2009-03-17-MRE-Invoke.ll Tue Mar 17 19:31:45 2009
@@ -0,0 +1,15 @@
+; RUN: llvm-as < %s | opt -deadargelim | llvm-dis
+; PR3807
+
+define internal { i32, i32 } @foo() {
+  ret {i32,i32} {i32 42, i32 4}
+}
+
+define i32 @bar() {
+  %x = invoke {i32,i32} @foo() to label %T unwind label %T2
+T:
+  %y = extractvalue {i32,i32} %x, 1
+  ret i32 %y
+T2:
+  unreachable
+}





More information about the llvm-commits mailing list