Skip to content

Commit 0d8606f

Browse files
svs-quictru
authored andcommitted
[RISCV] Pass sign-extended value to isInt check in expandMul (#150211)
In the `isInt` check that was added in #147661 we were passing the zero-extended `uint64_t` value instead of the sign-extended one. (cherry picked from commit d3937e2)
1 parent be21c13 commit 0d8606f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16013,7 +16013,7 @@ static SDValue expandMul(SDNode *N, SelectionDAG &DAG,
1601316013
uint64_t MulAmt = CNode->getZExtValue();
1601416014

1601516015
// Don't do this if the Xqciac extension is enabled and the MulAmt in simm12.
16016-
if (Subtarget.hasVendorXqciac() && isInt<12>(MulAmt))
16016+
if (Subtarget.hasVendorXqciac() && isInt<12>(CNode->getSExtValue()))
1601716017
return SDValue();
1601816018

1601916019
const bool HasShlAdd = Subtarget.hasStdExtZba() ||

llvm/test/CodeGen/RISCV/xqciac.ll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,30 @@ entry:
463463
%add = add nsw i32 %shlc1, %shlc2
464464
ret i32 %add
465465
}
466+
467+
define i32 @testmuliaddnegimm(i32 %a) {
468+
; RV32IM-LABEL: testmuliaddnegimm:
469+
; RV32IM: # %bb.0:
470+
; RV32IM-NEXT: slli a1, a0, 1
471+
; RV32IM-NEXT: add a0, a1, a0
472+
; RV32IM-NEXT: li a1, 3
473+
; RV32IM-NEXT: sub a0, a1, a0
474+
; RV32IM-NEXT: ret
475+
;
476+
; RV32IMXQCIAC-LABEL: testmuliaddnegimm:
477+
; RV32IMXQCIAC: # %bb.0:
478+
; RV32IMXQCIAC-NEXT: li a1, 3
479+
; RV32IMXQCIAC-NEXT: qc.muliadd a1, a0, -3
480+
; RV32IMXQCIAC-NEXT: mv a0, a1
481+
; RV32IMXQCIAC-NEXT: ret
482+
;
483+
; RV32IZBAMXQCIAC-LABEL: testmuliaddnegimm:
484+
; RV32IZBAMXQCIAC: # %bb.0:
485+
; RV32IZBAMXQCIAC-NEXT: li a1, 3
486+
; RV32IZBAMXQCIAC-NEXT: qc.muliadd a1, a0, -3
487+
; RV32IZBAMXQCIAC-NEXT: mv a0, a1
488+
; RV32IZBAMXQCIAC-NEXT: ret
489+
%mul = mul i32 %a, -3
490+
%add = add i32 %mul, 3
491+
ret i32 %add
492+
}

0 commit comments

Comments
 (0)