mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-02 23:26:31 +00:00
Implement a DAGCombine in MipsISelLowering.cpp which transforms the following
pattern: (add v0, (add v1, abs_lo(tjt))) => (add (add v0, v1), abs_lo(tjt)) "tjt" is a TargetJumpTable node. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158419 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -335,11 +335,11 @@ SelectAddr(SDNode *Parent, SDValue Addr, SDValue &Base, SDValue &Offset) {
|
||||
// lui $2, %hi($CPI1_0)
|
||||
// lwc1 $f0, %lo($CPI1_0)($2)
|
||||
if (Addr.getOperand(1).getOpcode() == MipsISD::Lo) {
|
||||
SDValue LoVal = Addr.getOperand(1);
|
||||
if (isa<ConstantPoolSDNode>(LoVal.getOperand(0)) ||
|
||||
isa<GlobalAddressSDNode>(LoVal.getOperand(0))) {
|
||||
SDValue LoVal = Addr.getOperand(1), Opnd0 = LoVal.getOperand(0);
|
||||
if (isa<ConstantPoolSDNode>(Opnd0) || isa<GlobalAddressSDNode>(Opnd0) ||
|
||||
isa<JumpTableSDNode>(Opnd0)) {
|
||||
Base = Addr.getOperand(0);
|
||||
Offset = LoVal.getOperand(0);
|
||||
Offset = Opnd0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -295,6 +295,7 @@ MipsTargetLowering(MipsTargetMachine &TM)
|
||||
setTargetDAGCombine(ISD::SELECT);
|
||||
setTargetDAGCombine(ISD::AND);
|
||||
setTargetDAGCombine(ISD::OR);
|
||||
setTargetDAGCombine(ISD::ADD);
|
||||
|
||||
setMinFunctionAlignment(HasMips64 ? 3 : 2);
|
||||
|
||||
@@ -733,6 +734,33 @@ static SDValue PerformORCombine(SDNode *N, SelectionDAG& DAG,
|
||||
DAG.getConstant(SMSize0, MVT::i32), And0.getOperand(0));
|
||||
}
|
||||
|
||||
static SDValue PerformADDCombine(SDNode *N, SelectionDAG& DAG,
|
||||
TargetLowering::DAGCombinerInfo &DCI,
|
||||
const MipsSubtarget* Subtarget) {
|
||||
// (add v0, (add v1, abs_lo(tjt))) => (add (add v0, v1), abs_lo(tjt))
|
||||
|
||||
if (DCI.isBeforeLegalizeOps())
|
||||
return SDValue();
|
||||
|
||||
SDValue Add = N->getOperand(1);
|
||||
|
||||
if (Add.getOpcode() != ISD::ADD)
|
||||
return SDValue();
|
||||
|
||||
SDValue Lo = Add.getOperand(1);
|
||||
|
||||
if ((Lo.getOpcode() != MipsISD::Lo) ||
|
||||
(Lo.getOperand(0).getOpcode() != ISD::TargetJumpTable))
|
||||
return SDValue();
|
||||
|
||||
EVT ValTy = N->getValueType(0);
|
||||
DebugLoc DL = N->getDebugLoc();
|
||||
|
||||
SDValue Add1 = DAG.getNode(ISD::ADD, DL, ValTy, N->getOperand(0),
|
||||
Add.getOperand(0));
|
||||
return DAG.getNode(ISD::ADD, DL, ValTy, Add1, Lo);
|
||||
}
|
||||
|
||||
SDValue MipsTargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI)
|
||||
const {
|
||||
SelectionDAG &DAG = DCI.DAG;
|
||||
@@ -753,6 +781,8 @@ SDValue MipsTargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI)
|
||||
return PerformANDCombine(N, DAG, DCI, Subtarget);
|
||||
case ISD::OR:
|
||||
return PerformORCombine(N, DAG, DCI, Subtarget);
|
||||
case ISD::ADD:
|
||||
return PerformADDCombine(N, DAG, DCI, Subtarget);
|
||||
}
|
||||
|
||||
return SDValue();
|
||||
|
Reference in New Issue
Block a user