Skip to content

[RISCV] Implement RISCVTTIImpl::getPreferredAddressingMode for HasVendorXCVmem #120533

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
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2329,6 +2329,15 @@ unsigned RISCVTTIImpl::getMaximumVF(unsigned ElemWidth, unsigned Opcode) const {
return std::max<unsigned>(1U, RegWidth.getFixedValue() / ElemWidth);
}

TTI::AddressingModeKind
RISCVTTIImpl::getPreferredAddressingMode(const Loop *L,
ScalarEvolution *SE) const {
if (ST->hasVendorXCVmem() && !ST->is64Bit())
return TTI::AMK_PostIndexed;

return BasicTTIImplBase::getPreferredAddressingMode(L, SE);
}

bool RISCVTTIImpl::isLSRCostLess(const TargetTransformInfo::LSRCost &C1,
const TargetTransformInfo::LSRCost &C2) {
// RISC-V specific here are "instruction number 1st priority".
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
llvm_unreachable("unknown register class");
}

TTI::AddressingModeKind getPreferredAddressingMode(const Loop *L,
ScalarEvolution *SE) const;

unsigned getRegisterClassForType(bool Vector, Type *Ty = nullptr) const {
if (Vector)
return RISCVRegisterClass::VRRC;
Expand Down
34 changes: 34 additions & 0 deletions llvm/test/CodeGen/RISCV/xcvmem-heuristic.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -O3 -mtriple=riscv32 -mattr=+m,+xcvmem -verify-machineinstrs < %s \
; RUN: | FileCheck %s --check-prefixes=CHECK

define i32 @test_heuristic(ptr %b, i32 %e, i1 %0) {
; CHECK-LABEL: test_heuristic:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: add a3, a0, a1
; CHECK-NEXT: andi a2, a2, 1
; CHECK-NEXT: .LBB0_1: # %loop
; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
; CHECK-NEXT: cv.lbu a1, (a3), 1
; CHECK-NEXT: addi a0, a0, 1
; CHECK-NEXT: beqz a2, .LBB0_1
; CHECK-NEXT: # %bb.2: # %exit
; CHECK-NEXT: mv a0, a1
; CHECK-NEXT: ret
entry:
%1 = getelementptr i8, ptr %b, i32 %e
br label %loop

loop: ; preds = %loop, %entry
%2 = phi ptr [ %b, %entry ], [ %7, %loop ]
%3 = phi ptr [ %1, %entry ], [ %8, %loop ]
%4 = load i8, ptr %2, align 1
%5 = load i8, ptr %3, align 1
%6 = zext i8 %5 to i32
%7 = getelementptr i8, ptr %2, i32 1
%8 = getelementptr i8, ptr %3, i32 1
br i1 %0, label %exit, label %loop

exit: ; preds = %loop
ret i32 %6
}
Loading