Skip to content

Commit 37ec0ec

Browse files
committed
[Clang][LoongArch] Match GCC behaviour when parsing FPRs in asm clobbers
There're four possible formats to refer a register in inline assembly, 1. Numeric name without dollar sign ("f0") 2. Numeric name with dollar sign ("$f0") 3. ABI name without dollar sign ("fa0") 4. ABI name with dollar sign ("$fa0") LoongArch GCC accepts 1 and 2 for FPRs before r15-8284[1] and all these formats after the chagne. But Clang supports only 2 and 4 for FPRs. The inconsistency has caused compatibility issues, such as QEMU's case[2]. This patch follows 0bbf3dd ("[Clang][LoongArch] Add GPR alias handling without `$` prefix") and accepts FPRs without dollar sign prefixes as well to keep aligned with GCC, avoiding future compatibility problems. Link: https://gcc.gnu.org/cgit/gcc/commit/?id=d0110185eb78f14a8e485f410bee237c9c71548d [1] Link: https://lore.kernel.org/qemu-devel/[email protected]/ [2]
1 parent 6543878 commit 37ec0ec

File tree

3 files changed

+54
-41
lines changed

3 files changed

+54
-41
lines changed

clang/lib/Basic/Targets/LoongArch.cpp

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -82,38 +82,46 @@ LoongArchTargetInfo::getGCCRegAliases() const {
8282
{{"s6", "$s6", "r29"}, "$r29"},
8383
{{"s7", "$s7", "r30"}, "$r30"},
8484
{{"s8", "$s8", "r31"}, "$r31"},
85-
{{"$fa0"}, "$f0"},
86-
{{"$fa1"}, "$f1"},
87-
{{"$fa2"}, "$f2"},
88-
{{"$fa3"}, "$f3"},
89-
{{"$fa4"}, "$f4"},
90-
{{"$fa5"}, "$f5"},
91-
{{"$fa6"}, "$f6"},
92-
{{"$fa7"}, "$f7"},
93-
{{"$ft0"}, "$f8"},
94-
{{"$ft1"}, "$f9"},
95-
{{"$ft2"}, "$f10"},
96-
{{"$ft3"}, "$f11"},
97-
{{"$ft4"}, "$f12"},
98-
{{"$ft5"}, "$f13"},
99-
{{"$ft6"}, "$f14"},
100-
{{"$ft7"}, "$f15"},
101-
{{"$ft8"}, "$f16"},
102-
{{"$ft9"}, "$f17"},
103-
{{"$ft10"}, "$f18"},
104-
{{"$ft11"}, "$f19"},
105-
{{"$ft12"}, "$f20"},
106-
{{"$ft13"}, "$f21"},
107-
{{"$ft14"}, "$f22"},
108-
{{"$ft15"}, "$f23"},
109-
{{"$fs0"}, "$f24"},
110-
{{"$fs1"}, "$f25"},
111-
{{"$fs2"}, "$f26"},
112-
{{"$fs3"}, "$f27"},
113-
{{"$fs4"}, "$f28"},
114-
{{"$fs5"}, "$f29"},
115-
{{"$fs6"}, "$f30"},
116-
{{"$fs7"}, "$f31"},
85+
{{"fa0", "$fa0", "f0"}, "$f0"},
86+
{{"fa1", "$fa1", "f1"}, "$f1"},
87+
{{"fa2", "$fa2", "f2"}, "$f2"},
88+
{{"fa3", "$fa3", "f3"}, "$f3"},
89+
{{"fa4", "$fa4", "f4"}, "$f4"},
90+
{{"fa5", "$fa5", "f5"}, "$f5"},
91+
{{"fa6", "$fa6", "f6"}, "$f6"},
92+
{{"fa7", "$fa7", "f7"}, "$f7"},
93+
{{"ft0", "$ft0", "f8"}, "$f8"},
94+
{{"ft1", "$ft1", "f9"}, "$f9"},
95+
{{"ft2", "$ft2", "f10"}, "$f10"},
96+
{{"ft3", "$ft3", "f11"}, "$f11"},
97+
{{"ft4", "$ft4", "f12"}, "$f12"},
98+
{{"ft5", "$ft5", "f13"}, "$f13"},
99+
{{"ft6", "$ft6", "f14"}, "$f14"},
100+
{{"ft7", "$ft7", "f15"}, "$f15"},
101+
{{"ft8", "$ft8", "f16"}, "$f16"},
102+
{{"ft9", "$ft9", "f17"}, "$f17"},
103+
{{"ft10", "$ft10", "f18"}, "$f18"},
104+
{{"ft11", "$ft11", "f19"}, "$f19"},
105+
{{"ft12", "$ft12", "f20"}, "$f20"},
106+
{{"ft13", "$ft13", "f21"}, "$f21"},
107+
{{"ft14", "$ft14", "f22"}, "$f22"},
108+
{{"ft15", "$ft15", "f23"}, "$f23"},
109+
{{"fs0", "$fs0", "f24"}, "$f24"},
110+
{{"fs1", "$fs1", "f25"}, "$f25"},
111+
{{"fs2", "$fs2", "f26"}, "$f26"},
112+
{{"fs3", "$fs3", "f27"}, "$f27"},
113+
{{"fs4", "$fs4", "f28"}, "$f28"},
114+
{{"fs5", "$fs5", "f29"}, "$f29"},
115+
{{"fs6", "$fs6", "f30"}, "$f30"},
116+
{{"fs7", "$fs7", "f31"}, "$f31"},
117+
{{"fcc0"}, "$fcc0"},
118+
{{"fcc1"}, "$fcc1"},
119+
{{"fcc2"}, "$fcc2"},
120+
{{"fcc3"}, "$fcc3"},
121+
{{"fcc4"}, "$fcc4"},
122+
{{"fcc5"}, "$fcc5"},
123+
{{"fcc6"}, "$fcc6"},
124+
{{"fcc7"}, "$fcc7"},
117125
};
118126
return llvm::ArrayRef(GCCRegAliases);
119127
}

clang/test/CodeGen/LoongArch/inline-asm-gcc-regs-error.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,4 @@ void test(void) {
88
register float a1 asm ("$f32");
99
// CHECK: :[[#@LINE+1]]:24: error: unknown register name '$foo' in asm
1010
register int a2 asm ("$foo");
11-
12-
/// Names not prefixed with '$' are invalid.
13-
14-
// CHECK: :[[#@LINE+1]]:26: error: unknown register name 'f0' in asm
15-
register float a5 asm ("f0");
16-
// CHECK: :[[#@LINE+1]]:26: error: unknown register name 'fa0' in asm
17-
register float a6 asm ("fa0");
18-
// CHECK: :[[#@LINE+1]]:15: error: unknown register name 'fcc0' in asm
19-
asm ("" ::: "fcc0");
2011
}

clang/test/CodeGen/LoongArch/inline-asm-gcc-regs.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,48 +79,62 @@ void test_s2() {
7979
// CHECK: call void asm sideeffect "", "{$f0}"(float undef)
8080
void test_f0() {
8181
register float a asm ("$f0");
82+
register float b asm ("f0");
8283
asm ("" :: "f" (a));
84+
asm ("" :: "f" (b));
8385
}
8486

8587
// CHECK-LABEL: @test_f14
8688
// CHECK: call void asm sideeffect "", "{$f14}"(float undef)
8789
void test_f14() {
8890
register float a asm ("$f14");
91+
register float b asm ("f14");
8992
asm ("" :: "f" (a));
93+
asm ("" :: "f" (b));
9094
}
9195

9296
// CHECK-LABEL: @test_f31
9397
// CHECK: call void asm sideeffect "", "{$f31}"(float undef)
9498
void test_f31() {
9599
register float a asm ("$f31");
100+
register float b asm ("f31");
96101
asm ("" :: "f" (a));
102+
asm ("" :: "f" (b));
97103
}
98104

99105
// CHECK-LABEL: @test_fa0
100106
// CHECK: call void asm sideeffect "", "{$f0}"(float undef)
101107
void test_fa0() {
102108
register float a asm ("$fa0");
109+
register float b asm ("fa0");
103110
asm ("" :: "f" (a));
111+
asm ("" :: "f" (b));
104112
}
105113

106114
// CHECK-LABEL: @test_ft1
107115
// CHECK: call void asm sideeffect "", "{$f9}"(float undef)
108116
void test_ft1() {
109117
register float a asm ("$ft1");
118+
register float b asm ("ft1");
110119
asm ("" :: "f" (a));
120+
asm ("" :: "f" (b));
111121
}
112122

113123
// CHECK-LABEL: @test_fs2
114124
// CHECK: call void asm sideeffect "", "{$f26}"(float undef)
115125
void test_fs2() {
116126
register float a asm ("$fs2");
127+
register float b asm ("fs2");
117128
asm ("" :: "f" (a));
129+
asm ("" :: "f" (b));
118130
}
119131

120132
// CHECK-LABEL: @test_fcc
121133
// CHECK: call void asm sideeffect "", "~{$fcc0}"()
122134
// CHECK: call void asm sideeffect "", "~{$fcc7}"()
123135
void test_fcc() {
124136
asm ("" ::: "$fcc0");
137+
asm ("" ::: "fcc0");
125138
asm ("" ::: "$fcc7");
139+
asm ("" ::: "fcc7");
126140
}

0 commit comments

Comments
 (0)