Skip to content

Commit 6083920

Browse files
authored
[Driver][SYCL] Improve -mlong-double behaviors (#6090)
The use of -mlong-double-64 should be allowed for host and target compilation. This was being filtered by a more general m_Group check. Update the driver so -mlong-double is properly passed through to the device compilation for SPIR-V offload targets, also restrict so only -mlong-double-64 is valid for device.
1 parent c90e287 commit 6083920

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

clang/lib/Driver/ToolChain.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,10 +1214,17 @@ llvm::opt::DerivedArgList *ToolChain::TranslateOffloadTargetArgs(
12141214
// AMD GPU is a special case, as -mcpu is required for the device
12151215
// compilation, except for SYCL which uses --offload-arch.
12161216
if (SameTripleAsHost || (getTriple().getArch() == llvm::Triple::amdgcn &&
1217-
DeviceOffloadKind != Action::OFK_SYCL))
1217+
DeviceOffloadKind != Action::OFK_SYCL)) {
12181218
DAL->append(A);
1219-
else
1220-
Modified = true;
1219+
continue;
1220+
}
1221+
// SPIR-V special case for -mlong-double
1222+
if (getTriple().isSPIR() &&
1223+
A->getOption().matches(options::OPT_LongDouble_Group)) {
1224+
DAL->append(A);
1225+
continue;
1226+
}
1227+
Modified = true;
12211228
continue;
12221229
}
12231230

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5664,7 +5664,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
56645664
}
56655665

56665666
if (Arg *A = Args.getLastArg(options::OPT_LongDouble_Group)) {
5667-
if (TC.getTriple().isX86() || TC.getTriple().isSPIR())
5667+
if (TC.getTriple().isX86())
5668+
A->render(Args, CmdArgs);
5669+
else if (TC.getTriple().isSPIR() &&
5670+
(A->getOption().getID() == options::OPT_mlong_double_64))
5671+
// Only allow for -mlong-double-64 for SPIR-V
56685672
A->render(Args, CmdArgs);
56695673
else if (TC.getTriple().isPPC() &&
56705674
(A->getOption().getID() != options::OPT_mlong_double_80))

clang/test/Driver/mlong-double-128.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// RUN: %clang -target powerpc64-pc-freebsd12 -c -### %s -mlong-double-128 2>&1 | FileCheck %s
33
// RUN: %clang -target powerpc64le-linux-musl -c -### %s -mlong-double-128 2>&1 | FileCheck %s
44
// RUN: %clang -target i686-linux-gnu -c -### %s -mlong-double-128 2>&1 | FileCheck %s
5-
// RUN: %clang -target spir64-unknown-unknown -c -### %s -mlong-double-128 2>&1 | FileCheck %s
65

76
// RUN: %clang -target x86_64-linux-musl -c -### %s -mlong-double-128 -mlong-double-80 2>&1 | FileCheck --implicit-check-not=-mlong-double-128 /dev/null
87
// RUN: %clang -target x86_64-linux-musl -c -### %s -mlong-double-80 -mlong-double-128 2>&1 | FileCheck %s
@@ -11,6 +10,10 @@
1110

1211
// RUN: %clang -target aarch64 -c -### %s -mlong-double-128 2>&1 | FileCheck --check-prefix=ERR %s
1312
// RUN: %clang -target powerpc -c -### %s -mlong-double-80 2>&1 | FileCheck --check-prefix=ERR2 %s
13+
// RUN: %clang -target spir64-unknown-unknown -c -### %s -mlong-double-128 2>&1 | FileCheck --check-prefix=ERR3 %s
14+
// RUN: %clang -target spir64-unknown-unknown -c -### %s -mlong-double-80 2>&1 | FileCheck --check-prefix=ERR4 %s
1415

1516
// ERR: error: unsupported option '-mlong-double-128' for target 'aarch64'
1617
// ERR2: error: unsupported option '-mlong-double-80' for target 'powerpc'
18+
// ERR3: error: unsupported option '-mlong-double-128' for target 'spir64-unknown-unknown'
19+
// ERR4: error: unsupported option '-mlong-double-80' for target 'spir64-unknown-unknown'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// -mlong-double-64 is valid for host and device for -fsycl
2+
// RUN: %clangxx -c -fsycl -mlong-double-64 -target x86_64-unknown-linux-gnu %s -### 2>&1 | FileCheck %s
3+
// CHECK: clang{{.*}} "-triple" "spir64-unknown-unknown"
4+
// CHECK-SAME: "-mlong-double-64"
5+
// CHECK: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu"
6+
// CHECK-SAME: "-mlong-double-64"
7+
8+
/// -mlong-double-128 and -mlong-double-80 are not supported for spir64.
9+
// RUN: %clangxx -c -fsycl -mlong-double-128 -target x86_64-unknown-linux-gnu %s -### 2>&1 | FileCheck --check-prefix=CHECK-128 %s
10+
// CHECK-128: error: unsupported option '-mlong-double-128' for target 'spir64-unknown-unknown'
11+
// CHECK-128-NOT: clang{{.*}} "-triple" "-spir64-unknown-unknown" {{.*}} "-mlong-double-128"
12+
13+
// RUN: %clangxx -c -fsycl -mlong-double-80 -target x86_64-unknown-linux-gnu %s -### 2>&1 | FileCheck --check-prefix=CHECK-80 %s
14+
// CHECK-80: error: unsupported option '-mlong-double-80' for target 'spir64-unknown-unknown'
15+
// CHECK-80-NOT: clang{{.*}} "-triple" "-spir64-unknown-unknown" {{.*}} "-mlong-double-80"

0 commit comments

Comments
 (0)