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

Commit d8c9dfc

Browse files
authored
Merge pull request #85 from parched/umlo
DAG: correctly legalize UMULO.
2 parents 8e1e6e6 + b02dd8a commit d8c9dfc

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
@@ -3477,17 +3477,24 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
34773477
LC = RTLIB::MUL_I128;
34783478
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Cannot expand this operation!");
34793479

3480-
// The high part is obtained by SRA'ing all but one of the bits of low
3481-
// part.
3482-
unsigned LoSize = VT.getSizeInBits();
3483-
SDValue HiLHS =
3484-
DAG.getNode(ISD::SRA, dl, VT, LHS,
3485-
DAG.getConstant(LoSize - 1, dl,
3486-
TLI.getPointerTy(DAG.getDataLayout())));
3487-
SDValue HiRHS =
3488-
DAG.getNode(ISD::SRA, dl, VT, RHS,
3489-
DAG.getConstant(LoSize - 1, dl,
3490-
TLI.getPointerTy(DAG.getDataLayout())));
3480+
SDValue HiLHS;
3481+
SDValue HiRHS;
3482+
if (isSigned) {
3483+
// The high part is obtained by SRA'ing all but one of the bits of low
3484+
// part.
3485+
unsigned LoSize = VT.getSizeInBits();
3486+
HiLHS =
3487+
DAG.getNode(ISD::SRA, dl, VT, LHS,
3488+
DAG.getConstant(LoSize - 1, dl,
3489+
TLI.getPointerTy(DAG.getDataLayout())));
3490+
HiRHS =
3491+
DAG.getNode(ISD::SRA, dl, VT, RHS,
3492+
DAG.getConstant(LoSize - 1, dl,
3493+
TLI.getPointerTy(DAG.getDataLayout())));
3494+
} else {
3495+
HiLHS = DAG.getConstant(0, dl, VT);
3496+
HiRHS = DAG.getConstant(0, dl, VT);
3497+
}
34913498

34923499
// Here we're passing the 2 arguments explicitly as 4 arguments that are
34933500
// 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)