118 lines · plain
1// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefixes=CHECK,NOINLINE,OPT_ATTR2// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -emit-llvm -O0 -o - | FileCheck %s --check-prefixes=CHECK,INLINE,OPT_ATTR3// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -emit-llvm -O1 -o - | FileCheck %s --check-prefixes=CHECK,INLINE,NOOPT_ATTR4// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefixes=CHECK,NOINLINE5// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute %s -emit-llvm -O0 -o - | FileCheck %s --check-prefixes=CHECK,INLINE,OPT_ATTR6// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute %s -emit-llvm -O1 -o - | FileCheck %s --check-prefixes=CHECK,INLINE,NOOPT_ATTR7 8// Tests that user functions will always be inlined.9// This includes exported functions and mangled entry point implementation functions.10// The unmangled entry functions must not be alwaysinlined.11 12#define MAX 10013 14float nums[MAX];15 16// Verify that all functions have the alwaysinline attribute17// NOINLINE: Function Attrs: alwaysinline18// NOINLINE: define hidden void @_Z4swapA100_jjj(ptr noundef byval([100 x i32]) align 4 %Buf, i32 noundef %ix1, i32 noundef %ix2) [[Attr:\#[0-9]+]]19// NOINLINE: ret void20// Swap the values of Buf at indices ix1 and ix221void swap(unsigned Buf[MAX], unsigned ix1, unsigned ix2) {22 float tmp = Buf[ix1];23 Buf[ix1] = Buf[ix2];24 Buf[ix2] = tmp;25}26 27// NOINLINE: Function Attrs: alwaysinline28// NOINLINE: define hidden void @_Z10BubbleSortA100_jj(ptr noundef byval([100 x i32]) align 4 %Buf, i32 noundef %size) [[Attr]]29// NOINLINE: ret void30// Inefficiently sort Buf in place31void BubbleSort(unsigned Buf[MAX], unsigned size) {32 bool swapped = true;33 while (swapped) {34 swapped = false;35 for (unsigned i = 1; i < size; i++) {36 if (Buf[i] < Buf[i-1]) {37 swap(Buf, i, i-1);38 swapped = true;39 }40 }41 }42}43 44// Note ExtAttr is the inlined export set of attribs45// CHECK: Function Attrs: alwaysinline46// CHECK: define noundef i32 @_Z11RemoveDupesA100_jj(ptr {{[a-z_ ]*}}noundef byval([100 x i32]) align 4 {{.*}}%Buf, i32 noundef %size) {{[a-z_ ]*}}[[Attr:\#[0-9]+]]47// CHECK: ret i3248// Sort Buf and remove any duplicate values49// returns the number of values left50export51unsigned RemoveDupes(unsigned Buf[MAX], unsigned size) {52 BubbleSort(Buf, size);53 unsigned insertPt = 0;54 for (unsigned i = 1; i < size; i++) {55 if (Buf[i] == Buf[i-1])56 insertPt++;57 else58 Buf[insertPt] = Buf[i];59 }60 return insertPt;61}62 63 64RWBuffer<unsigned> Indices;65 66// The mangled version of main only remains without inlining67// because it has internal linkage from the start68// Note main functions get the alwaysinline attrib, which Attr reflects69// NOINLINE: Function Attrs: alwaysinline70// NOINLINE: define internal void @_Z4mainj(i32 noundef %GI) [[Attr]]71// NOINLINE: ret void72 73// The unmangled version is not inlined, EntryAttr reflects that74// OPT_ATTR: Function Attrs: {{.*}}optnone75// NOOPT_ATTR-NOT: Function Attrs: {{.*}}optnone76// CHECK: define void @main() {{[a-z_ ]*}}[[EntryAttr:\#[0-9]+]]77// Make sure function calls are inlined when AlwaysInline is run78// This only leaves calls to llvm. intrinsics79// INLINE-NOT: call {{[^@]*}} @{{[^l][^l][^v][^m][^\.]}}80// CHECK: ret void81 82[numthreads(1,1,1)]83[shader("compute")]84void main(unsigned int GI : SV_GroupIndex) {85 unsigned tmpIndices[MAX];86 if (GI > MAX) return;87 for (unsigned i = 1; i < GI; i++)88 tmpIndices[i] = Indices[i];89 RemoveDupes(tmpIndices, GI);90 for (unsigned i = 1; i < GI; i++)91 tmpIndices[i] = Indices[i];92}93 94// The mangled version of main only remains without inlining95// because it has internal linkage from the start96// Note main functions get the alwaysinline attrib, which Attr reflects97// NOINLINE: Function Attrs: alwaysinline98// NOINLINE: define internal void @_Z6main10v() [[Attr]]99// NOINLINE: ret void100 101// The unmangled version is not inlined, EntryAttr reflects that102// OPT_ATTR: Function Attrs: {{.*}}optnone103// NOOPT_ATTR-NOT: Function Attrs: {{.*}}optnone104// CHECK: define void @main10() {{[a-z_ ]*}}[[EntryAttr]]105// Make sure function calls are inlined when AlwaysInline is run106// This only leaves calls to llvm. intrinsics107// INLINE-NOT: call {{[^@]*}} @{{[^l][^l][^v][^m][^\.]}}108// CHECK: ret void109 110[numthreads(1,1,1)]111[shader("compute")]112void main10() {113 main(10);114}115 116// CHECK: attributes [[Attr]] = {{.*}} alwaysinline117// CHECK: attributes [[EntryAttr]] = {{.*}} noinline118