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

Commit 4a6869c

Browse files
alexcrichtonarielb1
authored andcommitted
Merge pull request #85 from parched/umlo
DAG: correctly legalize UMULO.
2 parents 61fae73 + 7fb0600 commit 4a6869c

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3490,17 +3490,24 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
34903490
LC = RTLIB::MUL_I128;
34913491
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Cannot expand this operation!");
34923492

3493-
// The high part is obtained by SRA'ing all but one of the bits of low
3494-
// part.
3495-
unsigned LoSize = VT.getSizeInBits();
3496-
SDValue HiLHS =
3497-
DAG.getNode(ISD::SRA, dl, VT, LHS,
3498-
DAG.getConstant(LoSize - 1, dl,
3499-
TLI.getPointerTy(DAG.getDataLayout())));
3500-
SDValue HiRHS =
3501-
DAG.getNode(ISD::SRA, dl, VT, RHS,
3502-
DAG.getConstant(LoSize - 1, dl,
3503-
TLI.getPointerTy(DAG.getDataLayout())));
3493+
SDValue HiLHS;
3494+
SDValue HiRHS;
3495+
if (isSigned) {
3496+
// The high part is obtained by SRA'ing all but one of the bits of low
3497+
// part.
3498+
unsigned LoSize = VT.getSizeInBits();
3499+
HiLHS =
3500+
DAG.getNode(ISD::SRA, dl, VT, LHS,
3501+
DAG.getConstant(LoSize - 1, dl,
3502+
TLI.getPointerTy(DAG.getDataLayout())));
3503+
HiRHS =
3504+
DAG.getNode(ISD::SRA, dl, VT, RHS,
3505+
DAG.getConstant(LoSize - 1, dl,
3506+
TLI.getPointerTy(DAG.getDataLayout())));
3507+
} else {
3508+
HiLHS = DAG.getConstant(0, dl, VT);
3509+
HiRHS = DAG.getConstant(0, dl, VT);
3510+
}
35043511

35053512
// Here we're passing the 2 arguments explicitly as 4 arguments that are
35063513
// pre-lowered to the correct types. This all depends upon WideVT not
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: llc < %s -mtriple=thumbv6m-none-eabi | FileCheck %s
2+
3+
define i1 @unsigned_multiplication_did_overflow(i32, i32) {
4+
; CHECK-LABEL: unsigned_multiplication_did_overflow:
5+
entry-block:
6+
%2 = tail call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %0, i32 %1)
7+
%3 = extractvalue { i32, i1 } %2, 1
8+
ret i1 %3
9+
10+
; CHECK: mov{{s?}} r2, r1
11+
; CHECK: mov{{s?}} r1, #0
12+
; CHECK: mov{{s?}} r3, {{#0|r1}}
13+
; CHECK: bl __aeabi_lmul
14+
}
15+
16+
declare { i32, i1 } @llvm.umul.with.overflow.i32(i32, i32)

0 commit comments

Comments
 (0)