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

Commit 15d7c54

Browse files
rs-armJames Duley
authored and
James Duley
committed
Fix signed multiplication with overflow fallback.
For targets that don't have ISD::MULHS or ISD::SMUL_LOHI for the type and the double width type is illegal, then the two operands are sign extended to twice their size then multiplied to check for overflow. The extended upper halves were mismatched causing an incorrect result. This fixes the mismatch. A test was added for ARM V6-M where the bug was detected. Patch by James Duley. Differential Revision: https://reviews.llvm.org/D31807 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301404 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 1ef3b91 commit 15d7c54

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3481,11 +3481,11 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
34813481
// part.
34823482
unsigned LoSize = VT.getSizeInBits();
34833483
SDValue HiLHS =
3484-
DAG.getNode(ISD::SRA, dl, VT, RHS,
3484+
DAG.getNode(ISD::SRA, dl, VT, LHS,
34853485
DAG.getConstant(LoSize - 1, dl,
34863486
TLI.getPointerTy(DAG.getDataLayout())));
34873487
SDValue HiRHS =
3488-
DAG.getNode(ISD::SRA, dl, VT, LHS,
3488+
DAG.getNode(ISD::SRA, dl, VT, RHS,
34893489
DAG.getConstant(LoSize - 1, dl,
34903490
TLI.getPointerTy(DAG.getDataLayout())));
34913491

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 @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)