Skip to content

Commit 102e154

Browse files
authored
[SYCL][NFCI] Move default optimization level configuration (#7885)
Right now the front-end compiler modifies default optimization level in SYCL device compilation mode (upstream clang uses O0, whereas DPC++ uses O2). As some of CodeGen module patches landed to upstream, this difference causes conflicts and regresions when we pull changes from the upstream to the `sycl` branch. Current optimization level configuration is modeled after OpenCL compiler, which is a JIT compiler, so it doesn't use clang Driver. For DPC++ compiler it's more reasonable to make this type of changes in the driver to avoid significant divergence in LIT tests.
1 parent d43df4f commit 102e154

29 files changed

+86
-74
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4999,6 +4999,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
49994999
CmdArgs.push_back("-Wno-sycl-strict");
50005000
}
50015001

5002+
// Set O2 optimization level by default
5003+
if (!Args.getLastArg(options::OPT_O_Group))
5004+
CmdArgs.push_back("-O2");
5005+
50025006
// Add the integration header option to generate the header.
50035007
StringRef Header(D.getIntegrationHeader(Input.getBaseInput()));
50045008
if (!Header.empty()) {

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,9 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
579579
static unsigned getOptimizationLevel(ArgList &Args, InputKind IK,
580580
DiagnosticsEngine &Diags) {
581581
unsigned DefaultOpt = llvm::CodeGenOpt::None;
582-
if (((IK.getLanguage() == Language::OpenCL ||
583-
IK.getLanguage() == Language::OpenCLCXX) &&
584-
!Args.hasArg(OPT_cl_opt_disable)) ||
585-
Args.hasArg(OPT_fsycl_is_device))
582+
if ((IK.getLanguage() == Language::OpenCL ||
583+
IK.getLanguage() == Language::OpenCLCXX) &&
584+
!Args.hasArg(OPT_cl_opt_disable))
586585
DefaultOpt = llvm::CodeGenOpt::Default;
587586

588587
if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {

clang/test/CodeGenSYCL/address-space-cond-op.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@ struct S {
55
unsigned short x;
66
};
77

8-
// CHECK-LABEL: @_Z3foobR1SS_(
8+
// CHECK-LABEL: define {{[^@]+}}@_Z3foobR1SS_(
99
// CHECK: entry:
1010
// CHECK-NEXT: [[COND_ADDR:%.*]] = alloca i8, align 1
1111
// CHECK-NEXT: [[LHS_ADDR:%.*]] = alloca ptr addrspace(4), align 8
1212
// CHECK-NEXT: [[COND_ADDR_ASCAST:%.*]] = addrspacecast ptr [[COND_ADDR]] to ptr addrspace(4)
1313
// CHECK-NEXT: [[LHS_ADDR_ASCAST:%.*]] = addrspacecast ptr [[LHS_ADDR]] to ptr addrspace(4)
1414
// CHECK-NEXT: [[FROMBOOL:%.*]] = zext i1 [[COND:%.*]] to i8
15-
// CHECK-NEXT: store i8 [[FROMBOOL]], ptr addrspace(4) [[COND_ADDR_ASCAST]], align 1, [[TBAA12:!tbaa !.*]]
16-
// CHECK-NEXT: store ptr addrspace(4) [[LHS:%.*]], ptr addrspace(4) [[LHS_ADDR_ASCAST]], align 8, [[TBAA5:!tbaa !.*]]
15+
// CHECK-NEXT: store i8 [[FROMBOOL]], ptr addrspace(4) [[COND_ADDR_ASCAST]], align 1
16+
// CHECK-NEXT: store ptr addrspace(4) [[LHS:%.*]], ptr addrspace(4) [[LHS_ADDR_ASCAST]], align 8
1717
// CHECK-NEXT: [[RHS_ASCAST:%.*]] = addrspacecast ptr [[RHS:%.*]] to ptr addrspace(4)
18-
// CHECK-NEXT: [[TMP0:%.*]] = load i8, ptr addrspace(4) [[COND_ADDR_ASCAST]], align 1, [[TBAA12]], [[RNG14:!range !.*]]
18+
// CHECK-NEXT: [[TMP0:%.*]] = load i8, ptr addrspace(4) [[COND_ADDR_ASCAST]], align 1
1919
// CHECK-NEXT: [[TOBOOL:%.*]] = trunc i8 [[TMP0]] to i1
2020
// CHECK-NEXT: br i1 [[TOBOOL]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
2121
// CHECK: cond.true:
22-
// CHECK-NEXT: [[TMP1:%.*]] = load ptr addrspace(4), ptr addrspace(4) [[LHS_ADDR_ASCAST]], align 8, [[TBAA5]]
22+
// CHECK-NEXT: [[TMP1:%.*]] = load ptr addrspace(4), ptr addrspace(4) [[LHS_ADDR_ASCAST]], align 8
2323
// CHECK-NEXT: br label [[COND_END:%.*]]
2424
// CHECK: cond.false:
2525
// CHECK-NEXT: br label [[COND_END]]
2626
// CHECK: cond.end:
2727
// CHECK-NEXT: [[COND_LVALUE:%.*]] = phi ptr addrspace(4) [ [[TMP1]], [[COND_TRUE]] ], [ [[RHS_ASCAST]], [[COND_FALSE]] ]
28-
// CHECK-NEXT: call void @llvm.memcpy.p4.p4.i64(ptr addrspace(4) align 2 %agg.result, ptr addrspace(4) align 2 [[COND_LVALUE]], i64 2, i1 false), !tbaa.struct !{{[0-9]+}}
28+
// CHECK-NEXT: call void @llvm.memcpy.p4.p4.i64(ptr addrspace(4) align 2 [[AGG_RESULT:%.*]], ptr addrspace(4) align 2 [[COND_LVALUE]], i64 2, i1 false)
2929
// CHECK-NEXT: ret void
3030
//
3131
S foo(bool cond, S &lhs, S rhs) {

clang/test/CodeGenSYCL/check-direct-attribute-propagation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fno-sycl-force-inline-kernel-lambda -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown -disable-llvm-passes -sycl-std=2020 -opaque-pointers -emit-llvm -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -O2 -fno-sycl-force-inline-kernel-lambda -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown -disable-llvm-passes -sycl-std=2020 -opaque-pointers -emit-llvm -o - %s | FileCheck %s
22

33
// Tests for IR of [[intel::scheduler_target_fmax_mhz()]], [[intel::num_simd_work_items()]],
44
// [[intel::no_global_work_offset()]], [[intel::max_global_work_dim()]], [[sycl::reqd_sub_group_size()]],

clang/test/CodeGenSYCL/const-wg-init.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ int main() {
1515
const int WG_CONST = 10;
1616
});
1717
// CHECK: store i32 10, ptr addrspace(4) addrspacecast (ptr addrspace(3) @{{.*}}WG_CONST{{.*}} to ptr addrspace(4))
18-
// CHECK: %{{[0-9]+}} = call ptr @llvm.invariant.start.p4(i64 4, ptr addrspace(4) addrspacecast (ptr addrspace(3) @{{.*}}WG_CONST{{.*}} to ptr addrspace(4)))
1918
return 0;
2019
}

clang/test/CodeGenSYCL/functionptr-addrspace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ __attribute__((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
77
kernelFunc();
88
}
99

10-
// CHECK: define dso_local spir_func{{.*}}invoke_function{{.*}}(ptr nocapture noundef %fptr, ptr addrspace(4) nocapture noundef %ptr)
10+
// CHECK: define dso_local spir_func{{.*}}invoke_function{{.*}}(ptr noundef %fptr, ptr addrspace(4) noundef %ptr)
1111
void invoke_function(int (*fptr)(), int *ptr) {}
1212

1313
int f() { return 0; }

clang/test/CodeGenSYCL/group-local-memory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Check that SYCLLowerWGLocalMemory pass is added to the SYCL device
22
// compilation pipeline with the inliner pass (new Pass Manager).
33

4-
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm \
4+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm -O2 \
55
// RUN: -mdebug-pass Structure %s -o /dev/null 2>&1 \
66
// RUN: | FileCheck %s -check-prefixes=CHECK-INL,CHECK
77

clang/test/CodeGenSYCL/inline_asm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -opaque-pointers -emit-llvm -x c++ %s -o - | FileCheck %s
1+
// RUN: %clang_cc1 -O1 -fsycl-is-device -triple spir64-unknown-unknown -opaque-pointers -emit-llvm -x c++ %s -o - | FileCheck %s
22

33
class kernel;
44

clang/test/CodeGenSYCL/inlining.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown %s -S -emit-llvm -o - | FileCheck %s
1+
// RUN: %clang_cc1 -O1 -fsycl-is-device -triple spir64-unknown-unknown %s -S -emit-llvm -o - | FileCheck %s
2+
// RUN: %clang_cc1 -O0 -fsycl-is-device -triple spir64-unknown-unknown %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-O0
23

34
template <typename name, typename Func>
45
__attribute__((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
56
kernelFunc();
67
}
78

89
int main() {
10+
// CHECK-O0: noinline
911
// CHECK-NOT: noinline
1012
kernel_single_task<class kernel_function>([]() {});
1113
return 0;

clang/test/CodeGenSYCL/intel-fpga-loops.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple spir64-unknown-unknown -disable-llvm-passes -fsycl-is-device -emit-llvm %s -o - | FileCheck %s
1+
// RUN: %clang_cc1 -O2 -triple spir64-unknown-unknown -disable-llvm-passes -fsycl-is-device -emit-llvm %s -o - | FileCheck %s
22

33
// CHECK: br label %for.cond, !llvm.loop ![[MD_DLP:[0-9]+]]
44
// CHECK: br label %for.cond, !llvm.loop ![[MD_II:[0-9]+]]

0 commit comments

Comments
 (0)