Skip to content

Commit 8824602

Browse files
chbessonovaasl
authored andcommitted
[MSP430] Optimize A >> (8 + N) case
1 parent 4c766f6 commit 8824602

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/llvm/lib/Target/MSP430/MSP430ISelLowering.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,10 +949,17 @@ SDValue MSP430TargetLowering::LowerShifts(SDValue Op,
949949
uint64_t ShiftAmount = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
950950

951951
// Expand the stuff into sequence of shifts.
952-
// FIXME: for some shift amounts this might be done better!
953-
// E.g.: foo >> (8 + N) => sxt(swpb(foo)) >> N
954952
SDValue Victim = N->getOperand(0);
955953

954+
if ((Opc == ISD::SRA || Opc == ISD::SRL) && ShiftAmount > 8) {
955+
// E.g.: foo >> (8 + N) => sxt(swpb(foo)) >> N
956+
Victim = DAG.getNode(ISD::BSWAP, dl, VT, Victim);
957+
unsigned ExtOpc =
958+
Opc == ISD::SRA ? ISD::SIGN_EXTEND_INREG : ISD::ZERO_EXTEND;
959+
Victim = DAG.getNode(ExtOpc, dl, VT, Victim, DAG.getValueType(MVT::i8));
960+
ShiftAmount -= 8;
961+
}
962+
956963
if (Opc == ISD::SRL && ShiftAmount) {
957964
// Emit a special goodness here:
958965
// srl A, 1 => clrc; rrc A

src/llvm/test/CodeGen/MSP430/shifts.ll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ target triple = "msp430-elf"
55
define zeroext i8 @lshr8(i8 zeroext %a, i8 zeroext %cnt) nounwind readnone {
66
entry:
77
; CHECK-LABEL: lshr8:
8+
; CHECK: clrc
89
; CHECK: rrc.b
910
%shr = lshr i8 %a, %cnt
1011
ret i8 %shr
@@ -29,6 +30,7 @@ entry:
2930
define zeroext i16 @lshr16(i16 zeroext %a, i16 zeroext %cnt) nounwind readnone {
3031
entry:
3132
; CHECK-LABEL: lshr16:
33+
; CHECK: clrc
3234
; CHECK: rrc
3335
%shr = lshr i16 %a, %cnt
3436
ret i16 %shr
@@ -49,3 +51,26 @@ entry:
4951
%shl = shl i16 %a, %cnt
5052
ret i16 %shl
5153
}
54+
55+
define i16 @ashr10_i16(i16 %a) #0 {
56+
entry:
57+
; CHECK-LABEL: ashr10_i16:
58+
; CHECK: swpb r12
59+
; CHECK-NEXT: sxt r12
60+
; CHECK-NEXT: rra r12
61+
; CHECK-NEXT: rra r12
62+
%shr = ashr i16 %a, 10
63+
ret i16 %shr
64+
}
65+
66+
define i16 @lshr10_i16(i16 %a) #0 {
67+
entry:
68+
; CHECK-LABEL: lshr10_i16:
69+
; CHECK: swpb r12
70+
; CHECK-NEXT: mov.b r12, r12
71+
; CHECK-NEXT: clrc
72+
; CHECK-NEXT: rrc r12
73+
; CHECK-NEXT: rra r12
74+
%shr = lshr i16 %a, 10
75+
ret i16 %shr
76+
}

0 commit comments

Comments
 (0)