From b6ea2244b2dee81162cdae04a806e31c71f1e7ec Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Tue, 28 Apr 2015 12:47:49 +0200 Subject: [PATCH] R600/SI: handle undef loop conditions SIAnnotateControlFlow can't handle undef loop/branch conditions. Run SCCP pass to resolve undef branches and branch constant folding to convert into unconditional branches. A bit of quick testing also shows code size reductions. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=90056 --- lib/Target/R600/AMDGPUTargetMachine.cpp | 1 + lib/Target/R600/SIAnnotateControlFlow.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/Target/R600/AMDGPUTargetMachine.cpp b/lib/Target/R600/AMDGPUTargetMachine.cpp index b8de121..b36b88c 100644 --- a/lib/Target/R600/AMDGPUTargetMachine.cpp +++ b/lib/Target/R600/AMDGPUTargetMachine.cpp @@ -238,6 +238,7 @@ bool GCNPassConfig::addPreISel() { AMDGPUPassConfig::addPreISel(); addPass(createSinkingPass()); addPass(createSITypeRewriter()); + addPass(createSCCPPass()); addPass(createSIAnnotateControlFlowPass()); return false; } diff --git a/lib/Target/R600/SIAnnotateControlFlow.cpp b/lib/Target/R600/SIAnnotateControlFlow.cpp index d39ab3f..8f3136c 100644 --- a/lib/Target/R600/SIAnnotateControlFlow.cpp +++ b/lib/Target/R600/SIAnnotateControlFlow.cpp @@ -22,6 +22,7 @@ #include "llvm/Pass.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/SSAUpdater.h" +#include "llvm/Transforms/Utils/Local.h" using namespace llvm; @@ -320,6 +321,7 @@ bool SIAnnotateControlFlow::runOnFunction(Function &F) { for (df_iterator I = df_begin(&F.getEntryBlock()), E = df_end(&F.getEntryBlock()); I != E; ++I) { + ConstantFoldTerminator(*I, true); BranchInst *Term = dyn_cast((*I)->getTerminator()); if (!Term || Term->isUnconditional()) { -- 1.9.1