Skip to content

[X86] combineGatherScatter - ensure index / pointer sizes match when converting index shift to scale #140110

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
May 16, 2025

Conversation

RKSimon
Copy link
Collaborator

@RKSimon RKSimon commented May 15, 2025

The index value can sext/trunc to the pointer size before being scaled

Noticed while reviewing #139703

…converting index shift to scale

The index value will sext/trunc to the pointer size before being scaled

Noticed while reviewing llvm#139703
@llvmbot
Copy link
Member

llvmbot commented May 15, 2025

@llvm/pr-subscribers-backend-x86

Author: Simon Pilgrim (RKSimon)

Changes

The index value will sext/trunc to the pointer size before being scaled

Noticed while reviewing #139703


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

1 Files Affected:

  • (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+2-1)
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 9be3b39ce16fa..cc45067fbf300 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -56715,7 +56715,8 @@ static SDValue combineGatherScatter(SDNode *N, SelectionDAG &DAG,
   if (DCI.isBeforeLegalize()) {
     // Attempt to move shifted index into the address scale, allows further
     // index truncation below.
-    if (Index.getOpcode() == ISD::SHL && isa<ConstantSDNode>(Scale)) {
+    if (Index.getOpcode() == ISD::SHL && IndexSVT == PtrVT &&
+        isa<ConstantSDNode>(Scale)) {
       unsigned ScaleAmt = Scale->getAsZExtVal();
       assert(isPowerOf2_32(ScaleAmt) && "Scale must be a power of 2");
       unsigned Log2ScaleAmt = Log2_32(ScaleAmt);

@RKSimon RKSimon merged commit 882a4c5 into llvm:main May 16, 2025
9 of 10 checks passed
@RKSimon RKSimon deleted the x86-gather-scatter-index-scale branch May 16, 2025 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants