Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 6041df6

Browse files
committed
Backport rL288857 [CodeGen]
[CodeGen] Fix result type for SMULO/UMULO legalization On some platforms (like MSP430) the second element of the result structure for SMULO/UMULO may have a shorter type than the one returned by SetCC. We need to truncate it to the right type, or else some incorrect code may be generated later on. This fixes issue rust-lang/rust#37829 Patch by Vadzim Dambrouski! Differential Revision: https://reviews.llvm.org/D27154 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288857 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 87727ff commit 6041df6

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,6 +3425,15 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
34253425
TopHalf = DAG.getSetCC(dl, getSetCCResultType(VT), TopHalf,
34263426
DAG.getConstant(0, dl, VT), ISD::SETNE);
34273427
}
3428+
3429+
// Truncate the result if SetCC returns a larger type than needed.
3430+
EVT RType = Node->getValueType(1);
3431+
if (RType.getSizeInBits() < TopHalf.getValueSizeInBits())
3432+
TopHalf = DAG.getNode(ISD::TRUNCATE, dl, RType, TopHalf);
3433+
3434+
assert(RType.getSizeInBits() == TopHalf.getValueSizeInBits() &&
3435+
"Unexpected result type for S/UMULO legalization");
3436+
34283437
Results.push_back(BottomHalf);
34293438
Results.push_back(TopHalf);
34303439
break;

test/CodeGen/MSP430/umulo-16.ll

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: llc < %s -march=msp430 | FileCheck %s
2+
target datalayout = "e-m:e-p:16:16-i32:16:32-a:16-n8:16"
3+
target triple = "msp430"
4+
5+
define void @foo(i16 %arg) unnamed_addr {
6+
entry-block:
7+
br i1 undef, label %bb2, label %bb3
8+
9+
bb2: ; preds = %entry-block
10+
unreachable
11+
12+
bb3: ; preds = %entry-block
13+
%0 = call { i16, i1 } @llvm.umul.with.overflow.i16(i16 undef, i16 %arg)
14+
; CHECK: call
15+
%1 = extractvalue { i16, i1 } %0, 1
16+
%2 = call i1 @llvm.expect.i1(i1 %1, i1 false)
17+
br i1 %2, label %panic, label %bb5
18+
19+
bb5: ; preds = %bb3
20+
unreachable
21+
22+
panic: ; preds = %bb3
23+
unreachable
24+
}
25+
26+
; Function Attrs: nounwind readnone
27+
declare i1 @llvm.expect.i1(i1, i1) #0
28+
29+
; Function Attrs: nounwind readnone
30+
declare { i16, i1 } @llvm.umul.with.overflow.i16(i16, i16) #0
31+
32+
attributes #0 = { nounwind readnone }

0 commit comments

Comments
 (0)