From 37977076956fed8a1cb6f00b188e4636f23371be Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Sun, 8 Nov 2015 17:57:41 +0000 Subject: [PATCH] [FIX] Use unreachable to indicate dead code and repair dominance When we bail out early we make the partially build new code path practically dead, though it was not unreachable. To remove dominance problems we now make it not only dead but also prevent the control flow to join with the original code path, thus allow to use original values after the SCoP without any PHI nodes. This fixes bug 25447. llvm-svn: 252420 --- polly/lib/CodeGen/CodeGeneration.cpp | 7 ++- ...nce_problem_after_early_codegen_bailout.ll | 49 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 polly/test/Isl/CodeGen/dominance_problem_after_early_codegen_bailout.ll diff --git a/polly/lib/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp index 2b04f838dbca..1f2f0c021ecc 100644 --- a/polly/lib/CodeGen/CodeGeneration.cpp +++ b/polly/lib/CodeGen/CodeGeneration.cpp @@ -152,7 +152,12 @@ public: if (!NodeBuilder.preloadInvariantLoads()) { auto *FalseI1 = Builder.getFalse(); - Builder.GetInsertBlock()->getTerminator()->setOperand(0, FalseI1); + auto *SplitBBTerm = Builder.GetInsertBlock()->getTerminator(); + SplitBBTerm->setOperand(0, FalseI1); + auto *StartBBTerm = StartBlock->getTerminator(); + Builder.SetInsertPoint(StartBBTerm); + Builder.CreateUnreachable(); + StartBBTerm->eraseFromParent(); isl_ast_node_free(AstRoot); } else { diff --git a/polly/test/Isl/CodeGen/dominance_problem_after_early_codegen_bailout.ll b/polly/test/Isl/CodeGen/dominance_problem_after_early_codegen_bailout.ll new file mode 100644 index 000000000000..2d1f6c4ab6c2 --- /dev/null +++ b/polly/test/Isl/CodeGen/dominance_problem_after_early_codegen_bailout.ll @@ -0,0 +1,49 @@ +; RUN: opt %loadPolly -polly-codegen -analyze < %s +; +; This caused dominance problems at some point as we do bail out during +; code generation. Just verify it runs through. +; +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + +%struct.hashheader.0.5.10.165.180.185 = type { i16, i16, i16, i16, i16, i16, i32, i32, i32, i32, i32, i32, i32, i32, i32, [5 x i8], [13 x i8], i8, i8, i8, [228 x i16], [228 x i8], [228 x i8], [228 x i8], [228 x i8], [228 x i8], [228 x i8], [128 x i8], [100 x [11 x i8]], [100 x i32], [100 x i32], i16 } + +@hashheader = external global %struct.hashheader.0.5.10.165.180.185, align 4 + +; Function Attrs: nounwind uwtable +define void @strtoichar(i8* %in) #0 { +entry: + br i1 undef, label %land.rhs, label %for.end + +land.rhs: ; preds = %for.inc, %entry + %in.addr.012 = phi i8* [ undef, %for.inc ], [ %in, %entry ] + %0 = load i8, i8* %in.addr.012, align 1 + br i1 undef, label %for.end, label %for.body + +for.body: ; preds = %land.rhs + %idxprom = zext i8 %0 to i64 + %arrayidx = getelementptr inbounds %struct.hashheader.0.5.10.165.180.185, %struct.hashheader.0.5.10.165.180.185* @hashheader, i64 0, i32 27, i64 %idxprom + %1 = load i8, i8* %arrayidx, align 1 + %tobool = icmp eq i8 %1, 0 + br i1 %tobool, label %if.else, label %land.rhs.7 + +land.rhs.7: ; preds = %for.body + tail call void @stringcharlen() + br i1 undef, label %if.then, label %if.else + +if.then: ; preds = %land.rhs.7 + br label %for.inc + +if.else: ; preds = %land.rhs.7, %for.body + %2 = load i8, i8* %in.addr.012, align 1 + br label %for.inc + +for.inc: ; preds = %if.else, %if.then + %len.1 = phi i32 [ 0, %if.else ], [ undef, %if.then ] + br i1 undef, label %land.rhs, label %for.end + +for.end: ; preds = %for.inc, %land.rhs, %entry + ret void +} + +; Function Attrs: nounwind uwtable +declare void @stringcharlen() #0