mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 02:33:06 +01:00
[AVR] Optimize 16-bit comparison with constant
Reviewed By: dylanmckay Differential Revision: https://reviews.llvm.org/D93976
This commit is contained in:
parent
77d1393c15
commit
0d8fd96903
@ -455,6 +455,36 @@ static AVRCC::CondCodes intCCToAVRCC(ISD::CondCode CC) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns appropriate CP/CPI/CPC nodes code for the given 8/16-bit operands.
|
||||
SDValue AVRTargetLowering::getAVRCmp(SDValue LHS, SDValue RHS,
|
||||
SelectionDAG &DAG, SDLoc DL) const {
|
||||
assert((LHS.getSimpleValueType() == RHS.getSimpleValueType()) &&
|
||||
"LHS and RHS have different types");
|
||||
assert(((LHS.getSimpleValueType() == MVT::i16) ||
|
||||
(LHS.getSimpleValueType() == MVT::i8)) && "invalid comparison type");
|
||||
|
||||
SDValue Cmp;
|
||||
|
||||
if (LHS.getSimpleValueType() == MVT::i16 && dyn_cast<ConstantSDNode>(RHS)) {
|
||||
// Generate a CPI/CPC pair if RHS is a 16-bit constant.
|
||||
SDValue LHSlo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i8, LHS,
|
||||
DAG.getIntPtrConstant(0, DL));
|
||||
SDValue LHShi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i8, LHS,
|
||||
DAG.getIntPtrConstant(1, DL));
|
||||
SDValue RHSlo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i8, RHS,
|
||||
DAG.getIntPtrConstant(0, DL));
|
||||
SDValue RHShi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i8, RHS,
|
||||
DAG.getIntPtrConstant(1, DL));
|
||||
Cmp = DAG.getNode(AVRISD::CMP, DL, MVT::Glue, LHSlo, RHSlo);
|
||||
Cmp = DAG.getNode(AVRISD::CMPC, DL, MVT::Glue, LHShi, RHShi, Cmp);
|
||||
} else {
|
||||
// Generate ordinary 16-bit comparison.
|
||||
Cmp = DAG.getNode(AVRISD::CMP, DL, MVT::Glue, LHS, RHS);
|
||||
}
|
||||
|
||||
return Cmp;
|
||||
}
|
||||
|
||||
/// Returns appropriate AVR CMP/CMPC nodes and corresponding condition code for
|
||||
/// the given operands.
|
||||
SDValue AVRTargetLowering::getAVRCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,
|
||||
@ -567,7 +597,7 @@ SDValue AVRTargetLowering::getAVRCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,
|
||||
DAG.getIntPtrConstant(1, DL));
|
||||
Cmp = DAG.getNode(AVRISD::TST, DL, MVT::Glue, Top);
|
||||
} else {
|
||||
Cmp = DAG.getNode(AVRISD::CMP, DL, MVT::Glue, LHSlo, RHSlo);
|
||||
Cmp = getAVRCmp(LHSlo, RHSlo, DAG, DL);
|
||||
Cmp = DAG.getNode(AVRISD::CMPC, DL, MVT::Glue, LHShi, RHShi, Cmp);
|
||||
}
|
||||
} else if (VT == MVT::i64) {
|
||||
@ -605,7 +635,7 @@ SDValue AVRTargetLowering::getAVRCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,
|
||||
DAG.getIntPtrConstant(1, DL));
|
||||
Cmp = DAG.getNode(AVRISD::TST, DL, MVT::Glue, Top);
|
||||
} else {
|
||||
Cmp = DAG.getNode(AVRISD::CMP, DL, MVT::Glue, LHS0, RHS0);
|
||||
Cmp = getAVRCmp(LHS0, RHS0, DAG, DL);
|
||||
Cmp = DAG.getNode(AVRISD::CMPC, DL, MVT::Glue, LHS1, RHS1, Cmp);
|
||||
Cmp = DAG.getNode(AVRISD::CMPC, DL, MVT::Glue, LHS2, RHS2, Cmp);
|
||||
Cmp = DAG.getNode(AVRISD::CMPC, DL, MVT::Glue, LHS3, RHS3, Cmp);
|
||||
@ -619,7 +649,7 @@ SDValue AVRTargetLowering::getAVRCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,
|
||||
: DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i8,
|
||||
LHS, DAG.getIntPtrConstant(1, DL)));
|
||||
} else {
|
||||
Cmp = DAG.getNode(AVRISD::CMP, DL, MVT::Glue, LHS, RHS);
|
||||
Cmp = getAVRCmp(LHS, RHS, DAG, DL);
|
||||
}
|
||||
} else {
|
||||
llvm_unreachable("Invalid comparison size");
|
||||
|
@ -138,6 +138,8 @@ public:
|
||||
private:
|
||||
SDValue getAVRCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, SDValue &AVRcc,
|
||||
SelectionDAG &DAG, SDLoc dl) const;
|
||||
SDValue getAVRCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG,
|
||||
SDLoc dl) const;
|
||||
SDValue LowerShifts(SDValue Op, SelectionDAG &DAG) const;
|
||||
SDValue LowerDivRem(SDValue Op, SelectionDAG &DAG) const;
|
||||
SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
|
||||
|
@ -36,6 +36,22 @@ if.end:
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @cmpimm16(i16 %a) {
|
||||
; CHECK-LABEL: cmpimm16:
|
||||
; CHECK: cpi
|
||||
; CHECK-NEXT: cpc
|
||||
%cmp = icmp eq i16 %a, 4567
|
||||
br i1 %cmp, label %if.then, label %if.else
|
||||
if.then:
|
||||
tail call void @f3(i16 %a)
|
||||
br label %if.end
|
||||
if.else:
|
||||
tail call void @f4(i16 %a)
|
||||
br label %if.end
|
||||
if.end:
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @f5(i32)
|
||||
declare void @f6(i32)
|
||||
define void @cmp32(i32 %a, i32 %b) {
|
||||
@ -56,6 +72,24 @@ if.end:
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @cmpimm32(i32 %a) {
|
||||
; CHECK-LABEL: cmpimm32:
|
||||
; CHECK: cpi
|
||||
; CHECK-NEXT: cpc
|
||||
; CHECK-NEXT: cpc
|
||||
; CHECK-NEXT: cpc
|
||||
%cmp = icmp eq i32 %a, 6789343
|
||||
br i1 %cmp, label %if.then, label %if.else
|
||||
if.then:
|
||||
tail call void @f5(i32 %a)
|
||||
br label %if.end
|
||||
if.else:
|
||||
tail call void @f6(i32 %a)
|
||||
br label %if.end
|
||||
if.end:
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @f7(i64)
|
||||
declare void @f8(i64)
|
||||
define void @cmp64(i64 %a, i64 %b) {
|
||||
@ -80,6 +114,28 @@ if.end:
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @cmpimm64(i64 %a) {
|
||||
; CHECK-LABEL: cmpimm64:
|
||||
; CHECK: cpi
|
||||
; CHECK-NEXT: cpc
|
||||
; CHECK-NEXT: cpc
|
||||
; CHECK-NEXT: cpc
|
||||
; CHECK-NEXT: cpc
|
||||
; CHECK-NEXT: cpc
|
||||
; CHECK-NEXT: cpc
|
||||
; CHECK-NEXT: cpc
|
||||
%cmp = icmp eq i64 %a, 234566452
|
||||
br i1 %cmp, label %if.then, label %if.else
|
||||
if.then:
|
||||
tail call void @f7(i64 %a)
|
||||
br label %if.end
|
||||
if.else:
|
||||
tail call void @f8(i64 %a)
|
||||
br label %if.end
|
||||
if.end:
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @f9()
|
||||
declare void @f10()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user