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

via llvm-commits llvm-commits at lists.llvm.org
Thu May 15 10:44:53 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-x86

Author: Simon Pilgrim (RKSimon)

<details>
<summary>Changes</summary>

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

``````````

</details>


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


More information about the llvm-commits mailing list