Closed Quuxplusone closed 8 years ago
Attached bugpoint-reduced-function.ll.gz
(320899 bytes, application/x-gzip): failing IR
Aha, it looks like this is actually the -loop-reduce pass going awry, this
command will cause an inttoptr instruction to get inserted before the cleanuppad
opt -S ./bugpoint-reduced-function.ll -loop-reduce -verify
reduced IR:
target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
target triple = "i686-pc-windows-msvc"
declare i32 @_except_handler3(...) unnamed_addr
declare void @reserve()
define void @f() unnamed_addr personality i32 (...)* @_except_handler3 {
entry-block:
br label %start
start: ; preds = %throw, %start,
%entry-block
%phi1 = phi i8* [ undef, %entry-block ], [ %tmp96, %start ], [ %tmp96, %throw ]
%tmp96 = getelementptr inbounds i8, i8* %phi1, i32 1
br i1 undef, label %throw, label %start
pad: ; preds = %throw
%phi2 = phi i8* [ %tmp96, %throw ]
%cleanuppadi4.i.i.i = cleanuppad []
br label %loop_body
loop_body: ; preds = %iter, %pad
%tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %pad ]
%tmp100 = icmp eq i8* %tmp99, undef
br i1 %tmp100, label %unwind_out, label %iter
iter: ; preds = %loop_body
%tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
br i1 undef, label %unwind_out, label %loop_body
unwind_out: ; preds = %iter, %loop_body
cleanupret %cleanuppadi4.i.i.i unwind to caller
throw: ; preds = %start
invoke void @reserve()
to label %start unwind label %pad
}
The following patch fixes it:
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp
b/lib/Analysis/ScalarEvolutionExpander.cpp
index 86c2f50..e658131 100644
--- a/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -148,7 +148,7 @@ Value *SCEVExpander::InsertNoopCastOfTo(Value *V, Type *Ty)
{
IP = II->getNormalDest()->begin();
if (CatchPadInst *CPI = dyn_cast<CatchPadInst>(I))
IP = CPI->getNormalDest()->begin();
- while (isa<PHINode>(IP) || isa<LandingPadInst>(IP))
+ while (isa<PHINode>(IP) || isa<LandingPadInst>(IP) ||
isa<CleanupPadInst>(IP))
++IP;
return ReuseOrCreateCast(I, Ty, Op, IP);
}
Oh wow, thanks for the speedy fix! I'll apply locally and see if I run into anything else and let you know!
Fixed in r251393.
bugpoint-reduced-function.ll.gz
(320899 bytes, application/x-gzip)Created attachment 15166 failing IR
When running
llc
over the LLVM IR attached, it will emit:CleanupPadInst not the first non-PHI instruction in the block. %cleanuppadi4.i.i.i = cleanuppad [] The unwind destination does not have an exception handling instruction! invoke fastcc void @"ZN3vec13$LT$impl$GT$7reserve7reserve20h8370453893456365494E"(%"3.collections::vec::Vec"* noalias nonnull dereferenceable(12) %vectori4.i.i, i32 %227)
to label %normal-return5.i.normal-return10.i_crit_edgei4.i.i unwind label %unwind_custom_i4.i.i.i, !noalias !208
LLVM ERROR: Broken function found, compilation aborted!
When checking the IR, however, it looks like the
cleanuppad
instruction is the first non-phi instruction in the block?unwind_custom_i4.i.i.i:
%.lcssa178 = phi %"..." [ %175, %normal-return5i4.i.i.i ] %.pre.i.i.i.2672.i313i4.i.i.lcssa176 = phi %"..." [ %.pre.i.i.i.2672.i313i4.i.i, %normal-return5i4.i.i.i ] %cleanuppadi4.i.i.i = cleanuppad []
br label %loop_body.i.i.i.28i4.i.i.i
I wasn't really quite sure what was going wrong here, and it may be some invalid IR elsewhere in the file (sorry, I couldn't get bugpoint to reduce it further), but perhaps there's something odd going on?