diff options
| author | Hans Wennborg <hans@hanshq.net> | 2018-08-29 06:55:27 +0000 | 
|---|---|---|
| committer | Hans Wennborg <hans@hanshq.net> | 2018-08-29 06:55:27 +0000 | 
| commit | e0f3e9283f8249ad5253fbec10f68f3c81ae8b34 (patch) | |
| tree | bd2fd8ab5b851e898046da4523953b617d627ffc /llvm | |
| parent | 01235a4033cf1fe107e3d711108a9c2dd5fa8190 (diff) | |
| download | bcm5719-llvm-e0f3e9283f8249ad5253fbec10f68f3c81ae8b34.tar.gz bcm5719-llvm-e0f3e9283f8249ad5253fbec10f68f3c81ae8b34.zip  | |
LoopSink: Don't sink into blocks without an insertion point (PR38462)
In the PR, LoopSink was trying to sink into a catchswitch block, which
doesn't have a valid insertion point.
Differential Revision: https://reviews.llvm.org/D51307
llvm-svn: 340900
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/LoopSink.cpp | 8 | ||||
| -rw-r--r-- | llvm/test/Transforms/LICM/loopsink-pr38462.ll | 65 | 
2 files changed, 73 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopSink.cpp b/llvm/lib/Transforms/Scalar/LoopSink.cpp index 240d727d1e2..67bcbdca185 100644 --- a/llvm/lib/Transforms/Scalar/LoopSink.cpp +++ b/llvm/lib/Transforms/Scalar/LoopSink.cpp @@ -152,6 +152,14 @@ findBBsToSinkInto(const Loop &L, const SmallPtrSetImpl<BasicBlock *> &UseBBs,      }    } +  // Can't sink into blocks that have no valid insertion point. +  for (BasicBlock *BB : BBsToSinkInto) { +    if (BB->getFirstInsertionPt() == BB->end()) { +      BBsToSinkInto.clear(); +      break; +    } +  } +    // If the total frequency of BBsToSinkInto is larger than preheader frequency,    // do not sink.    if (adjustedSumFreq(BBsToSinkInto, BFI) > diff --git a/llvm/test/Transforms/LICM/loopsink-pr38462.ll b/llvm/test/Transforms/LICM/loopsink-pr38462.ll new file mode 100644 index 00000000000..146e2506b7e --- /dev/null +++ b/llvm/test/Transforms/LICM/loopsink-pr38462.ll @@ -0,0 +1,65 @@ +; RUN: opt -S -loop-sink < %s | FileCheck %s + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc19.13.26128" + +%struct.FontInfoData = type { i32 (...)** } +%struct.S = type { i8 } + +; CHECK: @pr38462 +; Make sure not to assert by trying to sink into catch.dispatch. + +define void @pr38462(%struct.FontInfoData* %this) personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) !prof !1 { +entry: +  %s = alloca %struct.S +  %call6 = call i32 @f() +  %tobool7 = icmp eq i32 %call6, 0 +  br i1 %tobool7, label %for.body.lr.ph, label %for.cond.cleanup + +for.body.lr.ph: +  %0 = getelementptr inbounds %struct.S, %struct.S* %s, i64 0, i32 0 +  br label %for.body + +for.cond.cleanup.loopexit: +  br label %for.cond.cleanup + +for.cond.cleanup: +  ret void + +for.body: +  %call2 = invoke i32 @f() to label %__try.cont unwind label %catch.dispatch + +catch.dispatch: +  %1 = catchswitch within none [label %__except] unwind to caller + +__except: +  %2 = catchpad within %1 [i8* null] +  catchret from %2 to label %__except3 + +__except3: +  call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull %0) +  %call.i = call zeroext i1 @g(%struct.S* nonnull %s) +  br i1 %call.i, label %if.then.i, label %exit + +if.then.i: +  %call2.i = call i32 @f() +  br label %exit + +exit: +  call void @llvm.lifetime.end.p0i8(i64 1, i8* nonnull %0) +  br label %__try.cont + +__try.cont: +  %call = call i32 @f() +  %tobool = icmp eq i32 %call, 0 +  br i1 %tobool, label %for.body, label %for.cond.cleanup.loopexit +} + +declare i32 @__C_specific_handler(...) +declare i32 @f() +declare zeroext i1 @g(%struct.S*) +declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) +declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) + +!1 = !{!"function_entry_count", i64 1} +  | 

