Skip to content

Commit 20e136a

Browse files
author
git apple-llvm automerger
committed
Merge commit '4a3daeb5595f' from apple/master into swift/master-next
2 parents 946dd5a + 4a3daeb commit 20e136a

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

clang/lib/Basic/Targets/AMDGPU.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,26 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
130130
"exec_hi", "tma_lo", "tma_hi", "tba_lo", "tba_hi",
131131
});
132132

133+
switch (*Name) {
134+
case 'I':
135+
Info.setRequiresImmediate(-16, 64);
136+
return true;
137+
case 'J':
138+
Info.setRequiresImmediate(-32768, 32767);
139+
return true;
140+
case 'A':
141+
case 'B':
142+
case 'C':
143+
Info.setRequiresImmediate();
144+
return true;
145+
default:
146+
break;
147+
}
148+
133149
StringRef S(Name);
134-
if (S == "A") {
150+
151+
if (S == "DA" || S == "DB") {
152+
Name++;
135153
Info.setRequiresImmediate();
136154
return true;
137155
}
@@ -203,6 +221,12 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
203221
// the constraint. In practice, it won't be changed unless the
204222
// constraint is longer than one character.
205223
std::string convertConstraint(const char *&Constraint) const override {
224+
225+
StringRef S(Constraint);
226+
if (S == "DA" || S == "DB") {
227+
return std::string("^") + std::string(Constraint++, 2);
228+
}
229+
206230
const char *Begin = Constraint;
207231
TargetInfo::ConstraintInfo Info("", "");
208232
if (validateAsmConstraint(Constraint, Info))

clang/test/CodeGenOpenCL/inline-asm-amdgcn.cl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,17 @@ kernel void test_agpr() {
3333
: "={a1}"(reg_a)
3434
: "{a1}"(reg_b));
3535
}
36+
37+
kernel void test_constraint_DA() {
38+
const long x = 0x200000001;
39+
int res;
40+
// CHECK: call i32 asm sideeffect "v_mov_b32 $0, $1 & 0xFFFFFFFF", "=v,^DA"(i64 8589934593)
41+
__asm volatile("v_mov_b32 %0, %1 & 0xFFFFFFFF" : "=v"(res) : "DA"(x));
42+
}
43+
44+
kernel void test_constraint_DB() {
45+
const long x = 0x200000001;
46+
int res;
47+
// CHECK: call i32 asm sideeffect "v_mov_b32 $0, $1 & 0xFFFFFFFF", "=v,^DB"(i64 8589934593)
48+
__asm volatile("v_mov_b32 %0, %1 & 0xFFFFFFFF" : "=v"(res) : "DB"(x));
49+
}

clang/test/Sema/inline-asm-validate-amdgpu.cl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,35 @@ kernel void test () {
1818
// vgpr constraints
1919
__asm__ ("v_mov_b32 %0, %1" : "=v" (vgpr) : "v" (imm) : );
2020

21-
// 'A' constraint
21+
// 'I' constraint (an immediate integer in the range -16 to 64)
22+
__asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "I" (imm) : );
23+
__asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "I" (-16) : );
24+
__asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "I" (64) : );
25+
__asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "I" (-17) : ); // expected-error {{value '-17' out of range for constraint 'I'}}
26+
__asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "I" (65) : ); // expected-error {{value '65' out of range for constraint 'I'}}
27+
28+
// 'J' constraint (an immediate 16-bit signed integer)
29+
__asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "J" (imm) : );
30+
__asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "J" (-32768) : );
31+
__asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "J" (32767) : );
32+
__asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "J" (-32769) : ); // expected-error {{value '-32769' out of range for constraint 'J'}}
33+
__asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "J" (32768) : ); // expected-error {{value '32768' out of range for constraint 'J'}}
34+
35+
// 'A' constraint (an immediate constant that can be inlined)
2236
__asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "A" (imm) : );
2337

38+
// 'B' constraint (an immediate 32-bit signed integer)
39+
__asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "B" (imm) : );
40+
41+
// 'C' constraint (an immediate 32-bit unsigned integer or 'A' constraint)
42+
__asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "C" (imm) : );
43+
44+
// 'DA' constraint (an immediate 64-bit constant that can be split into two 'A' constants)
45+
__asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "DA" (imm) : );
46+
47+
// 'DB' constraint (an immediate 64-bit constant that can be split into two 'B' constants)
48+
__asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "DB" (imm) : );
49+
2450
}
2551

2652
__kernel void

0 commit comments

Comments
 (0)