[llvm] r264344 - [LoopStrengthReduce] Don't hoist into a catchswitch

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 24 14:40:22 PDT 2016


Author: majnemer
Date: Thu Mar 24 16:40:22 2016
New Revision: 264344

URL: http://llvm.org/viewvc/llvm-project?rev=264344&view=rev
Log:
[LoopStrengthReduce] Don't hoist into a catchswitch

We try to hoist the insertion point as high as possible to encourage
sharing.  However, we must be careful not to hoist into a catchswitch as
it is both an EHPad and a terminator.

Added:
    llvm/trunk/test/Transforms/LoopStrengthReduce/pr27056.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=264344&r1=264343&r2=264344&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Thu Mar 24 16:40:22 2016
@@ -4353,6 +4353,11 @@ LSRInstance::HoistInsertPosition(BasicBl
     bool AllDominate = true;
     Instruction *BetterPos = nullptr;
     Instruction *Tentative = IDom->getTerminator();
+    // Don't bother attempting to insert before a catchswitch, their basic block
+    // cannot have other non-PHI instructions.
+    if (isa<CatchSwitchInst>(Tentative))
+      return IP;
+
     for (Instruction *Inst : Inputs) {
       if (Inst == Tentative || !DT.dominates(Inst, Tentative)) {
         AllDominate = false;
@@ -4426,7 +4431,7 @@ LSRInstance::AdjustInsertPositionForExpa
   while (isa<PHINode>(IP)) ++IP;
 
   // Ignore landingpad instructions.
-  while (!isa<TerminatorInst>(IP) && IP->isEHPad()) ++IP;
+  while (IP->isEHPad()) ++IP;
 
   // Ignore debug intrinsics.
   while (isa<DbgInfoIntrinsic>(IP)) ++IP;

Added: llvm/trunk/test/Transforms/LoopStrengthReduce/pr27056.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopStrengthReduce/pr27056.ll?rev=264344&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/LoopStrengthReduce/pr27056.ll (added)
+++ llvm/trunk/test/Transforms/LoopStrengthReduce/pr27056.ll Thu Mar 24 16:40:22 2016
@@ -0,0 +1,50 @@
+; RUN: opt < %s -loop-reduce -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"
+
+%struct.L = type { i8, i8* }
+
+declare i32 @__CxxFrameHandler3(...)
+
+ at GV1 = external global %struct.L*
+ at GV2 = external global %struct.L
+
+define void @b_copy_ctor() personality i32 (...)* @__CxxFrameHandler3 {
+entry:
+  %0 = load %struct.L*, %struct.L** @GV1, align 8
+  br label %for.cond
+
+for.cond:                                         ; preds = %call.i.noexc, %entry
+  %d.0 = phi %struct.L* [ %0, %entry ], [ %incdec.ptr, %call.i.noexc ]
+  invoke void @a_copy_ctor()
+          to label %call.i.noexc unwind label %catch.dispatch
+
+call.i.noexc:                                     ; preds = %for.cond
+  %incdec.ptr = getelementptr inbounds %struct.L, %struct.L* %d.0, i64 1
+  br label %for.cond
+
+catch.dispatch:                                   ; preds = %for.cond
+  %1 = catchswitch within none [label %catch] unwind to caller
+
+catch:                                            ; preds = %catch.dispatch
+  %2 = catchpad within %1 [i8* null, i32 64, i8* null]
+  %cmp16 = icmp eq %struct.L* %0, %d.0
+  br i1 %cmp16, label %for.end, label %for.body
+
+for.body:                                         ; preds = %for.body, %catch
+  %cmp = icmp eq %struct.L* @GV2, %d.0
+  br i1 %cmp, label %for.end, label %for.body
+
+for.end:                                          ; preds = %for.body, %catch
+  catchret from %2 to label %try.cont
+
+try.cont:                                         ; preds = %for.end
+  ret void
+}
+
+; CHECK-LABEL: define void @b_copy_ctor(
+; CHECK:       catchpad
+; CHECK-NEXT:  icmp eq %struct.L
+; CHECK-NEXT:  getelementptr {{.*}} i64 sub (i64 0, i64 ptrtoint (%struct.L* @GV2 to i64))
+
+declare void @a_copy_ctor()




More information about the llvm-commits mailing list