From f8814cf8b8ba8953add60078e304fd5a4113f9cc Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 2 Apr 2006 00:24:45 +0000 Subject: [PATCH] Prefer larger register classes over smaller ones when a register occurs in multiple register classes. This fixes PowerPC/2006-04-01-FloatDoubleExtend.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27334 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 1d05087b2a6..0956e8f9ad7 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -1663,21 +1663,30 @@ void RegsForValue::AddInlineAsmOperands(unsigned Code, SelectionDAG &DAG, static const TargetRegisterClass * isAllocatableRegister(unsigned Reg, MachineFunction &MF, const TargetLowering &TLI, const MRegisterInfo *MRI) { + MVT::ValueType FoundVT = MVT::Other; + const TargetRegisterClass *FoundRC = 0; for (MRegisterInfo::regclass_iterator RCI = MRI->regclass_begin(), E = MRI->regclass_end(); RCI != E; ++RCI) { + MVT::ValueType ThisVT = MVT::Other; + const TargetRegisterClass *RC = *RCI; // If none of the the value types for this register class are valid, we // can't use it. For example, 64-bit reg classes on 32-bit targets. - bool isLegal = false; for (TargetRegisterClass::vt_iterator I = RC->vt_begin(), E = RC->vt_end(); I != E; ++I) { if (TLI.isTypeLegal(*I)) { - isLegal = true; - break; + // If we have already found this register in a different register class, + // choose the one with the largest VT specified. For example, on + // PowerPC, we favor f64 register classes over f32. + if (FoundVT == MVT::Other || + MVT::getSizeInBits(FoundVT) < MVT::getSizeInBits(*I)) { + ThisVT = *I; + break; + } } } - if (!isLegal) continue; + if (ThisVT == MVT::Other) continue; // NOTE: This isn't ideal. In particular, this might allocate the // frame pointer in functions that need it (due to them not being taken @@ -1685,10 +1694,15 @@ isAllocatableRegister(unsigned Reg, MachineFunction &MF, // yet). This is a slight code pessimization, but should still work. for (TargetRegisterClass::iterator I = RC->allocation_order_begin(MF), E = RC->allocation_order_end(MF); I != E; ++I) - if (*I == Reg) - return RC; + if (*I == Reg) { + // We found a matching register class. Keep looking at others in case + // we find one with larger registers that this physreg is also in. + FoundRC = RC; + FoundVT = ThisVT; + break; + } } - return 0; + return FoundRC; } RegsForValue SelectionDAGLowering::