Currently, AMDGPU functions have `target-features` attribute populated with all default features for the target GPU. This is redundant because the backend can derive these defaults from the `target-cpu` attribute via `AMDGPUTargetMachine::getFeatureString()`. In this PR, for AMDGPU targets only: - Functions without explicit target attributes no longer emit `target-features` - Functions with `__attribute__((target(...)))` or `-target-feature` emit only features that differ from the target's defaults (delta) The backend already handles missing `target-features` correctly by falling back to the TargetMachine's defaults. A new cc1 flag `-famdgpu-emit-full-target-features` is added to emit full features when needed. Example: Before: ```llvm attributes #0 = { "target-cpu"="gfx90a" "target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot2-insts,..." } ``` After (default): ```llvm attributes #0 = { "target-cpu"="gfx90a" } ``` After (with explicit `+wavefrontsize32` override): ```llvm attributes #0 = { "target-cpu"="gfx90a" "target-features"="+wavefrontsize32" } ```
52 lines
2.1 KiB
Common Lisp
52 lines
2.1 KiB
Common Lisp
// REQUIRES: amdgpu-registered-target
|
|
|
|
// Test that by default, AMDGPU functions only emit delta target-features
|
|
// (features that differ from the target CPU's defaults). This reduces IR bloat.
|
|
|
|
// Default behavior for gfx90a: test_default has no target-features,
|
|
// test_explicit_attr has only the delta (+gfx11-insts).
|
|
// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx90a -emit-llvm -o - %s | FileCheck --check-prefix=GFX90A %s
|
|
|
|
// With -target-feature, both functions get the delta feature.
|
|
// gfx1030 defaults to wavefrontsize32, so +wavefrontsize64 is a delta.
|
|
// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1030 -target-feature +wavefrontsize64 -emit-llvm -o - %s | FileCheck --check-prefix=CMDLINE %s
|
|
|
|
// GFX90A-LABEL: define {{.*}} @test_default()
|
|
// GFX90A-SAME: #[[ATTR_DEFAULT:[0-9]+]]
|
|
// GFX90A-LABEL: define {{.*}} @test_explicit_attr()
|
|
// GFX90A-SAME: #[[ATTR_EXPLICIT:[0-9]+]]
|
|
//
|
|
// test_default should have target-cpu but NO target-features
|
|
// GFX90A: attributes #[[ATTR_DEFAULT]] = {
|
|
// GFX90A-SAME: "target-cpu"="gfx90a"
|
|
// GFX90A-NOT: "target-features"
|
|
// GFX90A-SAME: }
|
|
//
|
|
// test_explicit_attr should have target-cpu and ONLY the delta target-features
|
|
// GFX90A: attributes #[[ATTR_EXPLICIT]] = {
|
|
// GFX90A-SAME: "target-cpu"="gfx90a"
|
|
// GFX90A-SAME: "target-features"="+gfx11-insts"
|
|
// GFX90A-SAME: }
|
|
|
|
// With -target-feature +wavefrontsize64, test_default gets just that delta,
|
|
// test_explicit_attr gets both +gfx11-insts and +wavefrontsize64.
|
|
// CMDLINE-LABEL: define {{.*}} @test_default()
|
|
// CMDLINE-SAME: #[[ATTR_DEFAULT:[0-9]+]]
|
|
// CMDLINE-LABEL: define {{.*}} @test_explicit_attr()
|
|
// CMDLINE-SAME: #[[ATTR_EXPLICIT:[0-9]+]]
|
|
//
|
|
// CMDLINE: attributes #[[ATTR_DEFAULT]] = {
|
|
// CMDLINE-SAME: "target-cpu"="gfx1030"
|
|
// CMDLINE-SAME: "target-features"="+wavefrontsize64"
|
|
// CMDLINE-SAME: }
|
|
//
|
|
// CMDLINE: attributes #[[ATTR_EXPLICIT]] = {
|
|
// CMDLINE-SAME: "target-cpu"="gfx1030"
|
|
// CMDLINE-SAME: "target-features"="{{[^"]*}}+gfx11-insts{{[^"]*}}+wavefrontsize64{{[^"]*}}"
|
|
// CMDLINE-SAME: }
|
|
|
|
kernel void test_default() {}
|
|
|
|
__attribute__((target("gfx11-insts")))
|
|
void test_explicit_attr() {}
|