Skip to content

Conversation

@wangpc-pp
Copy link
Contributor

@wangpc-pp wangpc-pp commented Jul 10, 2025

The experimental result shows that we can generate more XTheadMemIdx
instructions when using preindexed addressing mode on SPEC CPU 2017.

-lsr-preferred-addressing-mode Num
none 47308
preindexed 54125
postindexed 50255
The experimental result shows that we can generate more XTheadMemIdx instructions when using preindexed addressing mode. | -lsr-preferred-addressing-mode | Num | |--------------------------------|-------| | none | 47308 | | preindexed | 54125 | | postindexed | 50255 |
@llvmbot
Copy link
Member

llvmbot commented Jul 10, 2025

@llvm/pr-subscribers-llvm-transforms

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

Author: Pengcheng Wang (wangpc-pp)

Changes

The experimental result shows that we can generate more XTheadMemIdx
instructions when using preindexed addressing mode.

-lsr-preferred-addressing-mode Num
none 47308
preindexed 54125
postindexed 50255

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

1 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp (+3)
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp index 67a51c12b508e..c07472a55c731 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp @@ -2709,6 +2709,9 @@ RISCVTTIImpl::getPreferredAddressingMode(const Loop *L, if (ST->hasVendorXCVmem() && !ST->is64Bit()) return TTI::AMK_PostIndexed; + if (ST->hasVendorXTHeadMemIdx()) + return TTI::AMK_PreIndexed; + return BasicTTIImplBase::getPreferredAddressingMode(L, SE); } 
@lenary
Copy link
Member

lenary commented Jul 10, 2025

Is it possible to add a test?

Copy link
Member

@lenary lenary left a comment

Choose a reason for hiding this comment

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

LGTM

; PRE-NEXT: addi a0, a0, 1949
; PRE-NEXT: .LBB0_1: # %loop
; PRE-NEXT: # =>This Inner Loop Header: Depth=1
; PRE-NEXT: th.lwib a2, (a1), 4, 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this better than NONE. We move the pointer increment from the store to the load which didn't change the size of the loop body, but now we have an extra instruction in the preheader.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment