From 979f66c7c79dd1f56ecaa74188e5f156a75c8125 Mon Sep 17 00:00:00 2001 From: Konstantin S Bobrovsky Date: Fri, 8 Jan 2021 20:43:33 -0800 Subject: [PATCH 1/4] [SYCL] Put constant initializer list data in non-generic addr space. Big constant initializer lists (>= 16 elements) were represented as a global in the generic address space. This is incorrect, as this is an alias AS, and allocation is not possible in it - compiler will have no clue where to really put data. Gen vector BE crashed on this pattern. The fix is to put this data into the same address space as a string literal. Signed-off-by: Konstantin S Bobrovsky --- clang/lib/CodeGen/CGExprAgg.cpp | 6 ++++ .../CodeGenSYCL/local_var_big_init_as.cpp | 34 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 clang/test/CodeGenSYCL/local_var_big_init_as.cpp diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 60ea1b2af037f..a8bc1a2b93a88 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -499,6 +499,12 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, CodeGen::CodeGenModule &CGM = CGF.CGM; ConstantEmitter Emitter(CGF); LangAS AS = ArrayQTy.getAddressSpace(); + if (CGM.getLangOpts().SYCLIsDevice && AS == LangAS::Default) { + // SYCL's default AS is 'generic', which can't be used to define constant + // initializer data in. It is reasonable to keep it in the same AS + // as string literals. + AS = CGM.getStringLiteralAddressSpace(); + } if (llvm::Constant *C = Emitter.tryEmitForInitializer(E, AS, ArrayQTy)) { auto GV = new llvm::GlobalVariable( CGM.getModule(), C->getType(), diff --git a/clang/test/CodeGenSYCL/local_var_big_init_as.cpp b/clang/test/CodeGenSYCL/local_var_big_init_as.cpp new file mode 100644 index 0000000000000..43906945e6030 --- /dev/null +++ b/clang/test/CodeGenSYCL/local_var_big_init_as.cpp @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice \ +// RUN: -emit-llvm -o - %s | FileCheck %s + +// This test checks that data for big constant initializer lists is placed +// into the global address space by the SYCL compiler. + +struct Test { + Test() : set{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 + // CHECK-DAG: @constinit = private unnamed_addr addrspace(1) constant + // CHECK: [32 x i32] + // CHECK: [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, + // CHECK: i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, + // CHECK: i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, + // CHECK: i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15 + // CHECK ], align 4 + // CHECK-NOT: @constinit = private unnamed_addr addrspace(0) + // CHECK-NOT: @constinit = private unnamed_addr addrspace(2) + // CHECK-NOT: @constinit = private unnamed_addr addrspace(3) + // CHECK-NOT: @constinit = private unnamed_addr addrspace(4) + } {}; + int set[32]; +}; + +__attribute__((sycl_device)) void bar(Test &x); + +__attribute__((sycl_device)) void zoo(int *y) { + const int vec[] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + Test mc; + bar(mc); +} From d739cc6e0187352ec0a7f703cf79fef6a2c428cf Mon Sep 17 00:00:00 2001 From: Konstantin S Bobrovsky Date: Tue, 12 Jan 2021 12:50:08 -0800 Subject: [PATCH 2/4] Fix clang formatting. Signed-off-by: Konstantin S Bobrovsky --- .../CodeGenSYCL/local_var_big_init_as.cpp | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/clang/test/CodeGenSYCL/local_var_big_init_as.cpp b/clang/test/CodeGenSYCL/local_var_big_init_as.cpp index 43906945e6030..f7ed229ea6a69 100644 --- a/clang/test/CodeGenSYCL/local_var_big_init_as.cpp +++ b/clang/test/CodeGenSYCL/local_var_big_init_as.cpp @@ -6,22 +6,21 @@ struct Test { Test() : set{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 - // CHECK-DAG: @constinit = private unnamed_addr addrspace(1) constant - // CHECK: [32 x i32] - // CHECK: [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, - // CHECK: i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, - // CHECK: i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, - // CHECK: i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15 - // CHECK ], align 4 - // CHECK-NOT: @constinit = private unnamed_addr addrspace(0) - // CHECK-NOT: @constinit = private unnamed_addr addrspace(2) - // CHECK-NOT: @constinit = private unnamed_addr addrspace(3) - // CHECK-NOT: @constinit = private unnamed_addr addrspace(4) - } {}; + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} {}; int set[32]; }; +// CHECK-DAG: @constinit = private unnamed_addr addrspace(1) constant +// CHECK: [32 x i32] +// CHECK: [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, +// CHECK: i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, +// CHECK: i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, +// CHECK: i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15 +// CHECK ], align 4 +// CHECK-NOT: @constinit = private unnamed_addr addrspace(0) +// CHECK-NOT: @constinit = private unnamed_addr addrspace(2) +// CHECK-NOT: @constinit = private unnamed_addr addrspace(3) +// CHECK-NOT: @constinit = private unnamed_addr addrspace(4) __attribute__((sycl_device)) void bar(Test &x); From 438cb532e622fc083525427f105eaeced62b3bb2 Mon Sep 17 00:00:00 2001 From: Konstantin S Bobrovsky Date: Tue, 12 Jan 2021 17:31:34 -0800 Subject: [PATCH 3/4] Removed redundant code from the test per review. Signed-off-by: Konstantin S Bobrovsky --- clang/test/CodeGenSYCL/local_var_big_init_as.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/clang/test/CodeGenSYCL/local_var_big_init_as.cpp b/clang/test/CodeGenSYCL/local_var_big_init_as.cpp index f7ed229ea6a69..69de8244fab8a 100644 --- a/clang/test/CodeGenSYCL/local_var_big_init_as.cpp +++ b/clang/test/CodeGenSYCL/local_var_big_init_as.cpp @@ -24,10 +24,7 @@ struct Test { __attribute__((sycl_device)) void bar(Test &x); -__attribute__((sycl_device)) void zoo(int *y) { - const int vec[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; +__attribute__((sycl_device)) void zoo() { Test mc; bar(mc); } From 30eb47f65951eaa7e7b7fefbcd833dccaa3a1977 Mon Sep 17 00:00:00 2001 From: Konstantin S Bobrovsky Date: Tue, 12 Jan 2021 18:45:19 -0800 Subject: [PATCH 4/4] added missing colon to the test per code review Signed-off-by: Konstantin S Bobrovsky --- clang/test/CodeGenSYCL/local_var_big_init_as.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/CodeGenSYCL/local_var_big_init_as.cpp b/clang/test/CodeGenSYCL/local_var_big_init_as.cpp index 69de8244fab8a..81461549d6a26 100644 --- a/clang/test/CodeGenSYCL/local_var_big_init_as.cpp +++ b/clang/test/CodeGenSYCL/local_var_big_init_as.cpp @@ -16,7 +16,7 @@ struct Test { // CHECK: i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, // CHECK: i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, // CHECK: i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15 -// CHECK ], align 4 +// CHECK: ], align 4 // CHECK-NOT: @constinit = private unnamed_addr addrspace(0) // CHECK-NOT: @constinit = private unnamed_addr addrspace(2) // CHECK-NOT: @constinit = private unnamed_addr addrspace(3)