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

Commit c99a03e

Browse files
alexcrichtonarielb1
authored andcommitted
Merge pull request #79 from parched/rust-smulo
Fix signed multiplication with overflow
2 parents 46de678 + 546bfff commit c99a03e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3494,11 +3494,11 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
34943494
// part.
34953495
unsigned LoSize = VT.getSizeInBits();
34963496
SDValue HiLHS =
3497-
DAG.getNode(ISD::SRA, dl, VT, RHS,
3497+
DAG.getNode(ISD::SRA, dl, VT, LHS,
34983498
DAG.getConstant(LoSize - 1, dl,
34993499
TLI.getPointerTy(DAG.getDataLayout())));
35003500
SDValue HiRHS =
3501-
DAG.getNode(ISD::SRA, dl, VT, LHS,
3501+
DAG.getNode(ISD::SRA, dl, VT, RHS,
35023502
DAG.getConstant(LoSize - 1, dl,
35033503
TLI.getPointerTy(DAG.getDataLayout())));
35043504

+16
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 @signed_multiplication_did_overflow(i32, i32) {
4+
; CHECK-LABEL: signed_multiplication_did_overflow:
5+
entry-block:
6+
%2 = tail call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %0, i32 %1)
7+
%3 = extractvalue { i32, i1 } %2, 1
8+
ret i1 %3
9+
10+
; CHECK: mov r2, r1
11+
; CHECK: asrs r1, r0, #31
12+
; CHECK: asrs r3, r2, #31
13+
; CHECK: bl __aeabi_lmul
14+
}
15+
16+
declare { i32, i1 } @llvm.smul.with.overflow.i32(i32, i32)

0 commit comments

Comments
 (0)