Skip to content

[RISCV] Pass sign-extended value to isInt check in expandMul #150211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 25, 2025

Conversation

svs-quic
Copy link
Contributor

In the isInt check that was added in #147661 we were passing the zero-extended uint64_t value instead of the sign-extended one.

In the isInt check that was added in # we were passing the zero-extended uint64_t
value instead of the sign-extended one.
@llvmbot
Copy link
Member

llvmbot commented Jul 23, 2025

@llvm/pr-subscribers-backend-risc-v

Author: Sudharsan Veeravalli (svs-quic)

Changes

In the isInt check that was added in #147661 we were passing the zero-extended uint64_t value instead of the sign-extended one.


Full diff: https://github.com/llvm/llvm-project/pull/150211.diff

1 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+1-1)
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 3918dd21bc09d..fa0196ff25339 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -16079,7 +16079,7 @@ static SDValue expandMul(SDNode *N, SelectionDAG &DAG,
   uint64_t MulAmt = CNode->getZExtValue();
 
   // Don't do this if the Xqciac extension is enabled and the MulAmt in simm12.
-  if (Subtarget.hasVendorXqciac() && isInt<12>(MulAmt))
+  if (Subtarget.hasVendorXqciac() && isInt<12>(CNode->getSExtValue()))
     return SDValue();
 
   const bool HasShlAdd = Subtarget.hasStdExtZba() ||

@topperc
Copy link
Collaborator

topperc commented Jul 23, 2025

Is it possible to test?

@svs-quic
Copy link
Contributor Author

Is it possible to test?

Have added a test now.

topperc added a commit to topperc/llvm-project that referenced this pull request Jul 24, 2025
Spotted while reviewing llvm#150211. If we're multiplying by -3 in i32
MulAmt contains 4,294,967,293 since we zero extend to uint64_t.
Adding 3 to this gives 0x100000000 which is a power of 2 and the log2
of that is 32, but we can't shift left by 32 in an i32.

We should use 0 instead of the shl in this case.

Normally we don't hit this case because decomeMulByConstant handles
it, but that's disabled by Qciac. And after llvm#150211 the path in
expandMul will also be unreachable. So I didn't add a test to avoid
messing with that review.
Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@topperc
Copy link
Collaborator

topperc commented Jul 24, 2025

I think we should backport this to the release branch.

@svs-quic svs-quic merged commit d3937e2 into llvm:main Jul 25, 2025
9 checks passed
@svs-quic svs-quic deleted the muliadd_fix branch July 25, 2025 00:17
@svs-quic svs-quic added this to the LLVM 21.x Release milestone Jul 25, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Jul 25, 2025
@svs-quic
Copy link
Contributor Author

/cherry-pick d3937e2

@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2025

/pull-request #150556

@llvmbot llvmbot moved this from Needs Triage to Done in LLVM Release Status Jul 25, 2025
topperc added a commit that referenced this pull request Jul 25, 2025
Spotted while reviewing #150211. If we're multiplying by -3 in i32
MulAmt contains 4,294,967,293 since we zero extend to uint64_t. Adding 3
to this gives 0x100000000 which is a power of 2 and the log2 of that is
32, but we can't shift left by 32 in an i32.

Detect this case and skip the transform. We could use 0, but we don't
handle the case for i64 so this seemed more consistent.

Normally we don't hit this case because decomposeMulByConstant handles
it, but that's disabled by Xqciac. And after #150211 the code in
expandMul is now unreachable for this case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

4 participants