[InstCombine] Don't RAUW tokens with undef
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 6 Nov 2015 21:26:32 +0000 (21:26 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 6 Nov 2015 21:26:32 +0000 (21:26 +0000)
Let SimplifyCFG remove unreachable BBs which define token instructions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252343 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstructionCombining.cpp
test/Transforms/InstCombine/token.ll [new file with mode: 0644]

index ac535f97bb1c6f15edfeba800fe36160eda22d15..f024ab1795ee25422da79832686220a35fb20b52 100644 (file)
@@ -3012,7 +3012,7 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
     while (EndInst != BB->begin()) {
       // Delete the next to last instruction.
       Instruction *Inst = &*--EndInst->getIterator();
-      if (!Inst->use_empty())
+      if (!Inst->use_empty() && !Inst->getType()->isTokenTy())
         Inst->replaceAllUsesWith(UndefValue::get(Inst->getType()));
       if (Inst->isEHPad()) {
         EndInst = Inst;
@@ -3022,7 +3022,8 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
         ++NumDeadInst;
         MadeIRChange = true;
       }
-      Inst->eraseFromParent();
+      if (!Inst->getType()->isTokenTy())
+        Inst->eraseFromParent();
     }
   }
 
diff --git a/test/Transforms/InstCombine/token.ll b/test/Transforms/InstCombine/token.ll
new file mode 100644 (file)
index 0000000..bb35d15
--- /dev/null
@@ -0,0 +1,21 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc18.0.0"
+
+declare i32 @__CxxFrameHandler3(...)
+
+define i8* @f() personality i32 (...)* @__CxxFrameHandler3 {
+bb:
+  unreachable
+
+unreachable:
+  %cl = cleanuppad []
+  cleanupret %cl unwind to caller
+}
+
+; CHECK: unreachable:
+; CHECK:   %cl = cleanuppad []
+; CHECK:   cleanupret %cl unwind to caller
+
+
+declare void @g(i8*)