Skip to content
This repository was archived by the owner on Sep 2, 2018. It is now read-only.

Commit 211dd8f

Browse files
committed
Expand MULHS for all types
Once MULHS was expanded, this exposed an issue where the condition register was thought to be 16-bit. This caused an attempt to copy a 16-bit register to an 8-bit register.
1 parent 16327d4 commit 211dd8f

File tree

5 files changed

+67
-35
lines changed

5 files changed

+67
-35
lines changed

lib/Target/AVR/AVRISelLowering.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,11 @@ AVRTargetLowering::AVRTargetLowering(AVRTargetMachine &tm)
137137
// Expand 16 bit multiplications.
138138
setOperationAction(ISD::SMUL_LOHI, MVT::i16, Expand);
139139
setOperationAction(ISD::UMUL_LOHI, MVT::i16, Expand);
140-
setOperationAction(ISD::MULHS, MVT::i16, Expand);
141-
setOperationAction(ISD::MULHU, MVT::i16, Expand);
140+
141+
for (MVT VT : MVT::integer_valuetypes()) {
142+
setOperationAction(ISD::MULHS, VT, Expand);
143+
setOperationAction(ISD::MULHU, VT, Expand);
144+
}
142145

143146
// Runtime library functions
144147
{
@@ -232,6 +235,12 @@ const char *AVRTargetLowering::getTargetNodeName(unsigned Opcode) const {
232235
}
233236
}
234237

238+
EVT AVRTargetLowering::getSetCCResultType(const DataLayout &DL, LLVMContext &,
239+
EVT VT) const {
240+
assert(!VT.isVector() && "No AVR SetCC type for vectors!");
241+
return MVT::i8;
242+
}
243+
235244
SDValue AVRTargetLowering::LowerShifts(SDValue Op, SelectionDAG &DAG) const {
236245
//:TODO: this function has to be completely rewritten to produce optimal
237246
// code, for now it's producing very long but correct code.

lib/Target/AVR/AVRISelLowering.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class AVRTargetLowering : public TargetLowering {
9494

9595
bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
9696

97+
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
98+
EVT VT) const override;
99+
97100
MachineBasicBlock *
98101
EmitInstrWithCustomInserter(MachineInstr *MI,
99102
MachineBasicBlock *MBB) const override;

test/CodeGen/AVR/issue-cannot-select-mulhs.ll

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; RUN: llc < %s -march=avr | FileCheck %s
2+
3+
define i1 @signed_multiplication_did_overflow(i8, i8) unnamed_addr {
4+
; CHECK-LABEL: signed_multiplication_did_overflow:
5+
entry-block:
6+
%2 = tail call { i8, i1 } @llvm.smul.with.overflow.i8(i8 %0, i8 %1)
7+
%3 = extractvalue { i8, i1 } %2, 1
8+
ret i1 %3
9+
10+
; Multiply, fill the low byte with the sign of the low byte via
11+
; arithmetic shifting, compare it to the high byte.
12+
;
13+
; CHECK: muls r24, r22
14+
; CHECK: mov [[HIGH:r[0-9]+]], r1
15+
; CHECK: mov [[LOW:r[0-9]+]], r0
16+
; CHECK: asr {{.*}}[[LOW]]
17+
; CHECK: asr {{.*}}[[LOW]]
18+
; CHECK: asr {{.*}}[[LOW]]
19+
; CHECK: asr {{.*}}[[LOW]]
20+
; CHECK: asr {{.*}}[[LOW]]
21+
; CHECK: asr {{.*}}[[LOW]]
22+
; CHECK: asr {{.*}}[[LOW]]
23+
; CHECK: ldi [[RET:r[0-9]+]], 1
24+
; CHECK: cp {{.*}}[[HIGH]], {{.*}}[[LOW]]
25+
; CHECK: brne [[LABEL:LBB[_0-9]+]]
26+
; CHECK: ldi {{.*}}[[RET]], 0
27+
; CHECK: {{.*}}[[LABEL]]
28+
; CHECK: ret
29+
}
30+
31+
declare { i8, i1 } @llvm.smul.with.overflow.i8(i8, i8)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: llc < %s -march=avr | FileCheck %s
2+
3+
define i1 @unsigned_multiplication_did_overflow(i8, i8) unnamed_addr {
4+
; CHECK-LABEL: unsigned_multiplication_did_overflow:
5+
entry-block:
6+
%2 = tail call { i8, i1 } @llvm.umul.with.overflow.i8(i8 %0, i8 %1)
7+
%3 = extractvalue { i8, i1 } %2, 1
8+
ret i1 %3
9+
10+
; Multiply, return if the high byte is zero
11+
;
12+
; CHECK: mul r{{[0-9]+}}, r{{[0-9]+}}
13+
; CHECK: mov [[HIGH:r[0-9]+]], r1
14+
; CHECK: ldi [[RET:r[0-9]+]], 1
15+
; CHECK: cpi {{.*}}[[HIGH]], 0
16+
; CHECK: brne [[LABEL:LBB[_0-9]+]]
17+
; CHECK: ldi {{.*}}[[RET]], 0
18+
; CHECK: {{.*}}[[LABEL]]
19+
; CHECK: ret
20+
}
21+
22+
declare { i8, i1 } @llvm.umul.with.overflow.i8(i8, i8)

0 commit comments

Comments
 (0)