Skip to content
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

update P7 32-bit partial vector load cost #108261

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 9 additions & 4 deletions llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,12 +802,17 @@ InstructionCost PPCTTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src,
// explicitly check this case. There are also corresponding store
// instructions.
unsigned MemBytes = Src->getPrimitiveSizeInBits();
if (ST->hasVSX() && IsAltivecType &&
(MemBytes == 64 || (ST->hasP8Vector() && MemBytes == 32)))
return 1;
Align AlignBytes = Alignment ? *Alignment : Align(1);
Copy link
Contributor

@diggerlin diggerlin Sep 17, 2024

Choose a reason for hiding this comment

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

we can put the definition of the variable before the
if (Opcode == Instruction::Load && MemBytes == 32 && AlignBytes < SrcBytes) )

unsigned SrcBytes = LT.second.getStoreSize();
if (ST->hasVSX() && IsAltivecType) {
if (MemBytes == 64 || (ST->hasP8Vector() && MemBytes == 32))
Copy link
Contributor

@diggerlin diggerlin Sep 18, 2024

Choose a reason for hiding this comment

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

nit: this maybe not related to the patch,

I think the variable MemBytes should be MemBits , otherwise it maybe cause mis_understand (it looks like compare with 64bytes and 32bytes)

if (MemBytes == 64 || (ST->hasP8Vector() && MemBytes == 32))

I think we can modify the variable name in the patch by the way?

return 1;
// Use lfiwax/xxspltw
if (Opcode == Instruction::Load && MemBytes == 32 && AlignBytes < SrcBytes)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am curious that why need the AlignBytes < SrcBytes here ?

Copy link
Collaborator Author

@RolandF77 RolandF77 Sep 18, 2024

Choose a reason for hiding this comment

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

If a partial vector (< 128 bits) is being loaded with a full vector aligned address (>= 128 bits), the load will be done as a full vector load since we know from alignment that it is safe. Therefore the cost of a partial vector load does not apply.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for explaining.

return 2;
}

// Aligned loads and stores are easy.
unsigned SrcBytes = LT.second.getStoreSize();
if (!SrcBytes || !Alignment || *Alignment >= SrcBytes)
return Cost;

Expand Down
7 changes: 5 additions & 2 deletions llvm/test/Analysis/CostModel/PowerPC/vsr_load_32_64.ll
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr8 -mattr=+vsx | FileCheck %s
; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr7 -mattr=+vsx | FileCheck --check-prefix=P7 %s
target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128-v128:128:128-n32:64"
target triple = "powerpc64-unknown-linux-gnu"

define i32 @loads(i32 %arg) {
; CHECK: cost of 1 {{.*}} load
; P7: cost of 2 {{.*}} load
Copy link
Contributor

@diggerlin diggerlin Sep 18, 2024

Choose a reason for hiding this comment

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

I would change to

opt < %s -passes="print" 2>&1 -disable-output -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr8 -mattr=+vsx | FileCheck %s -DCOST=1

opt < %s -passes="print" 2>&1 -disable-output -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr7 -mattr=+vsx | FileCheck %s -DCOST=2

add change

 ; CHECK: cost of 1 {{.*}} load
  ; P7: cost of 2 {{.*}} load

to
CHECK: cost of [[COST]] {{.*}} load

it is only a suggestion, feel free to keep it if you do not want to modify

load <4 x i8>, ptr undef, align 1

; CHECK: cost of 1 {{.*}} load
; CHECK, P7: cost of 1 {{.*}} load
load <8 x i8>, ptr undef, align 1

; CHECK: cost of 1 {{.*}} load
; P7: cost of 2 {{.*}} load
load <2 x i16>, ptr undef, align 2

; CHECK: cost of 1 {{.*}} load
; CHECK, P7: cost of 1 {{.*}} load
load <4 x i16>, ptr undef, align 2

ret i32 undef
Expand Down
Loading