10 changes: 5 additions & 5 deletions clang/test/CodeGenHLSL/inline-functions.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ float nums[MAX];

// Verify that all functions have the alwaysinline attribute
// NOINLINE: Function Attrs: alwaysinline
// NOINLINE: define void @"?swap@@YAXY0GE@III@Z"(ptr noundef byval([100 x i32]) align 4 %Buf, i32 noundef %ix1, i32 noundef %ix2) [[IntAttr:\#[0-9]+]]
// NOINLINE: define void @_Z4swapA100_jjj(ptr noundef byval([100 x i32]) align 4 %Buf, i32 noundef %ix1, i32 noundef %ix2) [[IntAttr:\#[0-9]+]]
// NOINLINE: ret void
// Swap the values of Buf at indices ix1 and ix2
void swap(unsigned Buf[MAX], unsigned ix1, unsigned ix2) {
Expand All @@ -25,7 +25,7 @@ void swap(unsigned Buf[MAX], unsigned ix1, unsigned ix2) {
}

// NOINLINE: Function Attrs: alwaysinline
// NOINLINE: define void @"?BubbleSort@@YAXY0GE@II@Z"(ptr noundef byval([100 x i32]) align 4 %Buf, i32 noundef %size) [[IntAttr]]
// NOINLINE: define void @_Z10BubbleSortA100_jj(ptr noundef byval([100 x i32]) align 4 %Buf, i32 noundef %size) [[IntAttr]]
// NOINLINE: ret void
// Inefficiently sort Buf in place
void BubbleSort(unsigned Buf[MAX], unsigned size) {
Expand All @@ -43,7 +43,7 @@ void BubbleSort(unsigned Buf[MAX], unsigned size) {

// Note ExtAttr is the inlined export set of attribs
// CHECK: Function Attrs: alwaysinline
// CHECK: define noundef i32 @"?RemoveDupes@@YAIY0GE@II@Z"(ptr {{[a-z_ ]*}}noundef byval([100 x i32]) align 4 %Buf, i32 noundef %size) {{[a-z_ ]*}}[[ExtAttr:\#[0-9]+]]
// CHECK: define noundef i32 @_Z11RemoveDupesA100_jj(ptr {{[a-z_ ]*}}noundef byval([100 x i32]) align 4 %Buf, i32 noundef %size) {{[a-z_ ]*}}[[ExtAttr:\#[0-9]+]]
// CHECK: ret i32
// Sort Buf and remove any duplicate values
// returns the number of values left
Expand All @@ -67,7 +67,7 @@ RWBuffer<unsigned> Indices;
// because it has internal linkage from the start
// Note main functions get the norecurse attrib, which IntAttr reflects
// NOINLINE: Function Attrs: alwaysinline
// NOINLINE: define internal void @"?main@@YAXI@Z"(i32 noundef %GI) [[IntAttr]]
// NOINLINE: define internal void @_Z4mainj(i32 noundef %GI) [[IntAttr]]
// NOINLINE: ret void

// The unmangled version is not inlined, EntryAttr reflects that
Expand All @@ -94,7 +94,7 @@ void main(unsigned int GI : SV_GroupIndex) {
// because it has internal linkage from the start
// Note main functions get the norecurse attrib, which IntAttr reflects
// NOINLINE: Function Attrs: alwaysinline
// NOINLINE: define internal void @"?main10@@YAXXZ"() [[IntAttr]]
// NOINLINE: define internal void @_Z6main10v() [[IntAttr]]
// NOINLINE: ret void

// The unmangled version is not inlined, EntryAttr reflects that
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenHLSL/semantics/GroupIndex-codegen.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void main(unsigned GI : SV_GroupIndex) {
//CHECK: define void @main() #[[#ENTRY_ATTR:]] {
//CHECK-NEXT: entry:
//CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
//CHECK-NEXT: call void @"?main@@YAXI@Z"(i32 %0)
//CHECK-NEXT: call void @_Z4mainj(i32 %0)
//CHECK-NEXT: ret void
//CHECK-NEXT: }

Expand Down
43 changes: 37 additions & 6 deletions clang/test/CodeGenHLSL/shift-mask.hlsl
Original file line number Diff line number Diff line change
@@ -1,35 +1,66 @@
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.3-library %s \
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s

int shl32(int V, int S) {
return V << S;
}

// CHECK: define noundef i32 @"?shl32{{[@$?.A-Za-z0-9_]+}}"(i32 noundef %V, i32 noundef %S) #0 {
// CHECK-LABEL: define noundef i32 @_Z5shl32ii(i32 noundef %V, i32 noundef %S) #0 {
// CHECK-DAG: %[[Masked:.*]] = and i32 %{{.*}}, 31
// CHECK-DAG: %{{.*}} = shl i32 %{{.*}}, %[[Masked]]

int shr32(int V, int S) {
return V >> S;
}

// CHECK: define noundef i32 @"?shr32{{[@$?.A-Za-z0-9_]+}}"(i32 noundef %V, i32 noundef %S) #0 {
// CHECK-LABEL: define noundef i32 @_Z5shr32ii(i32 noundef %V, i32 noundef %S) #0 {
// CHECK-DAG: %[[Masked:.*]] = and i32 %{{.*}}, 31
// CHECK-DAG: %{{.*}} = ashr i32 %{{.*}}, %[[Masked]]

int64_t shl64(int64_t V, int64_t S) {
return V << S;
}

// CHECK: define noundef i64 @"?shl64{{[@$?.A-Za-z0-9_]+}}"(i64 noundef %V, i64 noundef %S) #0 {
// CHECK-LABEL: define noundef i64 @_Z5shl64ll(i64 noundef %V, i64 noundef %S) #0 {
// CHECK-DAG: %[[Masked:.*]] = and i64 %{{.*}}, 63
// CHECK-DAG: %{{.*}} = shl i64 %{{.*}}, %[[Masked]]

int64_t shr64(int64_t V, int64_t S) {
return V >> S;
}

// CHECK: define noundef i64 @"?shr64{{[@$?.A-Za-z0-9_]+}}"(i64 noundef %V, i64 noundef %S) #0 {
// CHECK-LABEL: define noundef i64 @_Z5shr64ll(i64 noundef %V, i64 noundef %S) #0 {
// CHECK-DAG: %[[Masked:.*]] = and i64 %{{.*}}, 63
// CHECK-DAG: %{{.*}} = ashr i64 %{{.*}}, %[[Masked]]

uint shlu32(uint V, uint S) {
return V << S;
}

// CHECK-LABEL: define noundef i32 @_Z6shlu32jj(i32 noundef %V, i32 noundef %S) #0 {
// CHECK-DAG: %[[Masked:.*]] = and i32 %{{.*}}, 31
// CHECK-DAG: %{{.*}} = shl i32 %{{.*}}, %[[Masked]]

uint shru32(uint V, uint S) {
return V >> S;
}

// CHECK-LABEL: define noundef i32 @_Z6shru32jj(i32 noundef %V, i32 noundef %S) #0 {
// CHECK-DAG: %[[Masked:.*]] = and i32 %{{.*}}, 31
// CHECK-DAG: %{{.*}} = lshr i32 %{{.*}}, %[[Masked]]

uint64_t shlu64(uint64_t V, uint64_t S) {
return V << S;
}

// CHECK-LABEL: define noundef i64 @_Z6shlu64mm(i64 noundef %V, i64 noundef %S) #0 {
// CHECK-DAG: %[[Masked:.*]] = and i64 %{{.*}}, 63
// CHECK-DAG: %{{.*}} = shl i64 %{{.*}}, %[[Masked]]

uint64_t shru64(uint64_t V, uint64_t S) {
return V >> S;
}

// CHECK-LABEL: define noundef i64 @_Z6shru64mm(i64 noundef %V, i64 noundef %S) #0 {
// CHECK-DAG: %[[Masked:.*]] = and i64 %{{.*}}, 63
// CHECK-DAG: %{{.*}} = lshr i64 %{{.*}}, %[[Masked]]
7 changes: 3 additions & 4 deletions clang/test/CodeGenHLSL/sret_output.hlsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.3-library %s \
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s

// FIXME: add semantic to a.
Expand All @@ -10,10 +9,10 @@ struct S {


// Make sure sret parameter is generated.
// CHECK:define internal void @"?ps_main@@YA?AUS@@XZ"(ptr dead_on_unwind noalias writable sret(%struct.S) align 4 %agg.result)
// CHECK:define internal void @_Z7ps_mainv(ptr dead_on_unwind noalias writable sret(%struct.S) align 4 %agg.result)
// FIXME: change it to real value instead of poison value once semantic is add to a.
// Make sure the function with sret is called.
// CHECK:call void @"?ps_main@@YA?AUS@@XZ"(ptr poison)
// CHECK:call void @_Z7ps_mainv(ptr poison)
[shader("pixel")]
S ps_main() {
S s;
Expand Down
14 changes: 7 additions & 7 deletions clang/test/CodeGenHLSL/static-local-ctor.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ void InitBuf(RWBuffer<int> buf) {
}

// CHECK-NOT: _Init_thread_epoch
// CHECK: define internal void @"?main@@YAXXZ"
// CHECK: define internal void @_Z4mainv
// CHECK-NEXT: entry:
// CHECK-NEXT: [[Tmp1:%.*]] = alloca %"class.hlsl::RWBuffer"
// CHECK-NEXT: [[Tmp2:%.*]] = load i32, ptr
// CHECK-NEXT: [[Tmp3:%.*]] = and i32 [[Tmp2]], 1
// CHECK-NEXT: [[Tmp4:%.*]] = icmp eq i32 [[Tmp3]], 0
// CHECK-NEXT: br i1 [[Tmp4]]
// CHECK-NEXT: [[Tmp2:%.*]] = load i8, ptr @_ZGVZ4mainvE5mybuf
// CHECK-NEXT: [[Tmp3:%.*]] = icmp eq i8 [[Tmp2]], 0
// CHECK-NEXT: br i1 [[Tmp3]]
// CHECK-NOT: _Init_thread_header
// CHECK: init:
// CHECK-NEXT: = or i32 [[Tmp2]], 1
// CHECK: init.check:
// CHECK-NEXT: call void @_ZN4hlsl8RWBufferIiEC1Ev
// CHECK-NEXT: store i8 1, ptr @_ZGVZ4mainvE5mybuf
// CHECK-NOT: _Init_thread_footer


Expand Down
7 changes: 3 additions & 4 deletions clang/test/CodeGenHLSL/static_global_and_function_in_cb.hlsl
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.3-library %s \
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s

// CHECK-DAG: @[[CB:.+]] = external constant { float }

cbuffer A {
float a;
// CHECK-DAG:@b = internal global float 3.000000e+00, align 4
// CHECK-DAG:@_ZL1b = internal global float 3.000000e+00, align 4
static float b = 3;
// CHECK:load float, ptr @[[CB]], align 4
// CHECK:load float, ptr @b, align 4
// CHECK:load float, ptr @_ZL1b, align 4
float foo() { return a + b; }
}

Expand Down
8 changes: 4 additions & 4 deletions clang/test/CodeGenHLSL/this-assignment-overload.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void main() {
}

// This test makes a probably safe assumption that HLSL 202x includes operator overloading for assignment operators.
// CHECK: define linkonce_odr noundef i32 @"?getFirst@Pair@@QAAHXZ"(ptr noundef nonnull align 4 dereferenceable(8) %this) #0 align 2 {
// CHECK: define linkonce_odr noundef i32 @_ZN4Pair8getFirstEv(ptr noundef nonnull align 4 dereferenceable(8) %this) #0 align 2 {
// CHECK-NEXT:entry:
// CHECK-NEXT:%this.addr = alloca ptr, align 4
// CHECK-NEXT:%Another = alloca %struct.Pair, align 4
Expand All @@ -37,19 +37,19 @@ void main() {
// CHECK-NEXT:%Second = getelementptr inbounds nuw %struct.Pair, ptr %Another, i32 0, i32 1
// CHECK-NEXT:store i32 10, ptr %Second, align 4
// CHECK-NEXT:call void @llvm.memcpy.p0.p0.i32(ptr align 4 %agg.tmp, ptr align 4 %Another, i32 8, i1 false)
// CHECK-NEXT:call void @"??4Pair@@QAAXU0@@Z"(ptr noundef nonnull align 4 dereferenceable(8) %this1, ptr noundef byval(%struct.Pair) align 4 %agg.tmp)
// CHECK-NEXT:call void @_ZN4PairaSES_(ptr noundef nonnull align 4 dereferenceable(8) %this1, ptr noundef byval(%struct.Pair) align 4 %agg.tmp)
// CHECK-NEXT:%First2 = getelementptr inbounds nuw %struct.Pair, ptr %this1, i32 0, i32 0
// CHECK-NEXT:%0 = load i32, ptr %First2, align 4
// CHECK-NEXT:ret i32 %0

// CHECK: define linkonce_odr noundef i32 @"?getSecond@Pair@@QAAHXZ"(ptr noundef nonnull align 4 dereferenceable(8) %this) #0 align 2 {
// CHECK: define linkonce_odr noundef i32 @_ZN4Pair9getSecondEv(ptr noundef nonnull align 4 dereferenceable(8) %this) #0 align 2 {
// CHECK-NEXT:entry:
// CHECK-NEXT:%this.addr = alloca ptr, align 4
// CHECK-NEXT:%agg.tmp = alloca %struct.Pair, align 4
// CHECK-NEXT:store ptr %this, ptr %this.addr, align 4
// CHECK-NEXT:%this1 = load ptr, ptr %this.addr, align 4
// CHECK-NEXT:call void @llvm.memset.p0.i32(ptr align 4 %agg.tmp, i8 0, i32 8, i1 false)
// CHECK-NEXT:call void @"??4Pair@@QAAXU0@@Z"(ptr noundef nonnull align 4 dereferenceable(8) %this1, ptr noundef byval(%struct.Pair) align 4 %agg.tmp)
// CHECK-NEXT:call void @_ZN4PairaSES_(ptr noundef nonnull align 4 dereferenceable(8) %this1, ptr noundef byval(%struct.Pair) align 4 %agg.tmp)
// CHECK-NEXT:%Second = getelementptr inbounds nuw %struct.Pair, ptr %this1, i32 0, i32 1
// CHECK-NEXT:%0 = load i32, ptr %Second, align 4
// CHECK-NEXT:ret i32 %0
7 changes: 2 additions & 5 deletions clang/test/CodeGenHLSL/this-assignment.hlsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -disable-llvm-passes -o - -hlsl-entry main %s | FileCheck %s
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -emit-llvm -disable-llvm-passes -o - -hlsl-entry main %s | FileCheck %s

struct Pair {
int First;
Expand Down Expand Up @@ -40,7 +39,7 @@ void main() {
// CHECK-NEXT:%Another = alloca %struct.Pair, align 4
// CHECK-NEXT:store ptr %this, ptr %this.addr, align 4
// CHECK-NEXT:%this1 = load ptr, ptr %this.addr, align 4
// CHECK-NEXT:call void @llvm.memcpy.p0.p0.i32(ptr align 4 %Another, ptr align 4 @"__const.?getFirst@Pair@@QAAHXZ.Another", i32 8, i1 false)
// CHECK-NEXT:call void @llvm.memcpy.p0.p0.i32(ptr align 4 %Another, ptr align 4 @__const._ZN4Pair8getFirstEv.Another, i32 8, i1 false)
// CHECK-NEXT:call void @llvm.memcpy.p0.p0.i32(ptr align 4 %this1, ptr align 4 %Another, i32 8, i1 false)
// CHECK-NEXT:%First = getelementptr inbounds nuw %struct.Pair, ptr %this1, i32 0, i32 0

Expand All @@ -56,14 +55,12 @@ void main() {

// CHECK-LABEL: define {{.*}}DoSilly
// CHECK-NEXT:entry:
// CHECK-NEXT: [[ResPtr:%.*]] = alloca ptr
// CHECK-NEXT: [[ThisPtrAddr:%.*]] = alloca ptr
// CHECK-NEXT: store ptr [[AggRes:%.*]], ptr [[ResPtr]]
// CHECK-NEXT: store ptr {{.*}}, ptr [[ThisPtrAddr]]
// CHECK-NEXT: [[ThisPtr:%.*]] = load ptr, ptr [[ThisPtrAddr]]
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[ThisPtr]], ptr align 4 [[Obj:%.*]], i32 8, i1 false)
// CHECK-NEXT: [[FirstAddr:%.*]] = getelementptr inbounds nuw %struct.Pair, ptr [[ThisPtr]], i32 0, i32 0
// CHECK-NEXT: [[First:%.*]] = load i32, ptr [[FirstAddr]]
// CHECK-NEXT: [[FirstPlusTwo:%.*]] = add nsw i32 [[First]], 2
// CHECK-NEXT: store i32 [[FirstPlusTwo]], ptr [[FirstAddr]]
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[AggRes]], ptr align 4 [[Obj]], i32 8, i1 false)
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 {{.*}}, ptr align 4 [[Obj]], i32 8, i1 false)
4 changes: 2 additions & 2 deletions clang/test/CodeGenHLSL/this-reference.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ void main() {
}

// This tests reference like `this` in HLSL
// CHECK: %call = call noundef i32 @"?getFirst@Pair@@QAAHXZ"(ptr noundef nonnull align 4 dereferenceable(8) %Vals)
// CHECK: %call = call noundef i32 @_ZN4Pair8getFirstEv(ptr noundef nonnull align 4 dereferenceable(8) %Vals)
// CHECK-NEXT: %First = getelementptr inbounds nuw %struct.Pair, ptr %Vals, i32 0, i32 0
// CHECK-NEXT: store i32 %call, ptr %First, align 4
// CHECK-NEXT: %call1 = call noundef float @"?getSecond@Pair@@QAAMXZ"(ptr noundef nonnull align 4 dereferenceable(8) %Vals)
// CHECK-NEXT: %call1 = call noundef float @_ZN4Pair9getSecondEv(ptr noundef nonnull align 4 dereferenceable(8) %Vals)
// CHECK-NEXT: %Second = getelementptr inbounds nuw %struct.Pair, ptr %Vals, i32 0, i32 1

// CHECK: [[Pair:![0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Pair"
Expand Down