From 95a2c8f1d0f29ce2a5ec8c41dac8b406aef88c68 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Tue, 17 Nov 2009 19:15:50 +0000 Subject: [PATCH] Enable -split-phi-edges by default, except when -regalloc=local. The local register allocator doesn't like it when LiveVariables is run. We should also disable edge splitting under -O0, but that has to wait a bit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89125 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/PHIElimination.cpp | 18 +++++++++++++++--- test/CodeGen/X86/2008-04-15-LiveVariableBug.ll | 1 + test/CodeGen/X86/stack-color-with-reg.ll | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/CodeGen/PHIElimination.cpp b/lib/CodeGen/PHIElimination.cpp index c4f2cc7a75d..fc6574290b3 100644 --- a/lib/CodeGen/PHIElimination.cpp +++ b/lib/CodeGen/PHIElimination.cpp @@ -21,6 +21,7 @@ #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineRegisterInfo.h" +#include "llvm/CodeGen/RegAllocRegistry.h" #include "llvm/Function.h" #include "llvm/Target/TargetMachine.h" #include "llvm/ADT/SmallPtrSet.h" @@ -39,7 +40,7 @@ STATISTIC(NumSplits, "Number of critical edges split on demand"); static cl::opt SplitEdges("split-phi-edges", cl::desc("Split critical edges during phi elimination"), - cl::init(false), cl::Hidden); + cl::init(true), cl::Hidden); char PHIElimination::ID = 0; static RegisterPass @@ -47,10 +48,21 @@ X("phi-node-elimination", "Eliminate PHI nodes for register allocation"); const PassInfo *const llvm::PHIEliminationID = &X; +namespace llvm { FunctionPass *createLocalRegisterAllocator(); } + +// Should we run edge splitting? +static bool shouldSplitEdges() { + // Edge splitting breaks the local register allocator. It cannot tolerate + // LiveVariables being run. + if (RegisterRegAlloc::getDefault() == createLocalRegisterAllocator) + return false; + return SplitEdges; +} + void llvm::PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const { AU.addPreserved(); AU.addPreserved(); - if (SplitEdges) { + if (shouldSplitEdges()) { AU.addRequired(); } else { AU.setPreservesCFG(); @@ -67,7 +79,7 @@ bool llvm::PHIElimination::runOnMachineFunction(MachineFunction &Fn) { bool Changed = false; // Split critical edges to help the coalescer - if (SplitEdges) + if (shouldSplitEdges()) for (MachineFunction::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) Changed |= SplitPHIEdges(Fn, *I); diff --git a/test/CodeGen/X86/2008-04-15-LiveVariableBug.ll b/test/CodeGen/X86/2008-04-15-LiveVariableBug.ll index 83eb61aed43..2aea9c5ebcc 100644 --- a/test/CodeGen/X86/2008-04-15-LiveVariableBug.ll +++ b/test/CodeGen/X86/2008-04-15-LiveVariableBug.ll @@ -1,5 +1,6 @@ ; RUN: llc < %s -mtriple=x86_64-apple-darwin ; RUN: llc < %s -mtriple=x86_64-apple-darwin -relocation-model=pic -disable-fp-elim -O0 -regalloc=local +; PR5534 %struct.CGPoint = type { double, double } %struct.NSArray = type { %struct.NSObject } diff --git a/test/CodeGen/X86/stack-color-with-reg.ll b/test/CodeGen/X86/stack-color-with-reg.ll index 0f32a50fc5b..61cff05a023 100644 --- a/test/CodeGen/X86/stack-color-with-reg.ll +++ b/test/CodeGen/X86/stack-color-with-reg.ll @@ -1,6 +1,6 @@ ; RUN: llc < %s -mtriple=x86_64-apple-darwin10 -relocation-model=pic -disable-fp-elim -color-ss-with-regs -stats -info-output-file - > %t ; RUN: grep stackcoloring %t | grep "stack slot refs replaced with reg refs" | grep 6 -; RUN: grep asm-printer %t | grep 177 +; RUN: grep asm-printer %t | grep 175 type { [62 x %struct.Bitvec*] } ; type %0 type { i8* } ; type %1 -- 2.11.0