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

Commit 546bfff

Browse files
rs-armarielb1
authored andcommitted
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 46de678 commit 546bfff

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

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)