[llvm] r264926 - [IndVarSimplify] Don't insert after a catchswitch

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 30 14:12:06 PDT 2016


Author: majnemer
Date: Wed Mar 30 16:12:06 2016
New Revision: 264926

URL: http://llvm.org/viewvc/llvm-project?rev=264926&view=rev
Log:
[IndVarSimplify] Don't insert after a catchswitch

Widening a PHI requires us to insert a trunc.
The logical place for this trunc is in the same BB as the PHI.
This is not possible if the BB is terminated by a catchswitch.

This fixes PR27133.

Added:
    llvm/trunk/test/Transforms/IndVarSimplify/pr27133.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=264926&r1=264925&r2=264926&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Wed Mar 30 16:12:06 2016
@@ -1283,6 +1283,12 @@ Instruction *WidenIV::widenIVUse(NarrowI
       if (UsePhi->getNumOperands() != 1)
         truncateIVUse(DU, DT, LI);
       else {
+        // Widening the PHI requires us to insert a trunc.  The logical place
+        // for this trunc is in the same BB as the PHI.  This is not possible if
+        // the BB is terminated by a catchswitch.
+        if (isa<CatchSwitchInst>(UsePhi->getParent()->getTerminator()))
+          return nullptr;
+
         PHINode *WidePhi =
           PHINode::Create(DU.WideDef->getType(), 1, UsePhi->getName() + ".wide",
                           UsePhi);

Added: llvm/trunk/test/Transforms/IndVarSimplify/pr27133.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/pr27133.ll?rev=264926&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/pr27133.ll (added)
+++ llvm/trunk/test/Transforms/IndVarSimplify/pr27133.ll Wed Mar 30 16:12:06 2016
@@ -0,0 +1,38 @@
+; RUN: opt -indvars -S < %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"
+
+define i32 @fn2() personality i32 (...)* @__CxxFrameHandler3 {
+entry:
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.inc, %entry
+  %c.0 = phi i32 [ %inc, %for.inc ], [ 0, %entry ]
+; CHECK: %[[WIDE:.*]] = phi i64
+; CHECK: %[[NORM:.*]] = phi i32
+; CHECK: invoke void @fn1(i64 %[[WIDE]])
+  %idxprom = sext i32 %c.0 to i64
+  invoke void @fn1(i64 %idxprom)
+          to label %for.inc unwind label %catch.dispatch
+
+catch.dispatch:                                   ; preds = %for.cond
+  %c.0.lcssa = phi i32 [ %c.0, %for.cond ]
+; CHECK: %[[LCSSA:.*]] = phi i32 [ %[[NORM]],
+  %0 = catchswitch within none [label %catch] unwind to caller
+
+catch:                                            ; preds = %catch.dispatch
+  %1 = catchpad within %0 [i8* null, i32 64, i8* null]
+  catchret from %1 to label %exit
+
+exit:
+; CHECK: ret i32 %[[LCSSA]]
+  ret i32 %c.0.lcssa
+
+for.inc:                                          ; preds = %for.cond
+  %inc = add nsw nuw i32 %c.0, 1
+  br label %for.cond
+}
+
+declare void @fn1(i64 %idxprom)
+
+declare i32 @__CxxFrameHandler3(...)




More information about the llvm-commits mailing list