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

Commit 923d3f3

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 923d3f3

File tree

5 files changed

+36
-35
lines changed

5 files changed

+36
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
11+
declare { i8, i1 } @llvm.smul.with.overflow.i8(i8, i8)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
11+
declare { i8, i1 } @llvm.umul.with.overflow.i8(i8, i8)

0 commit comments

Comments
 (0)