Skip to content

Commit aede24e

Browse files
committed
[PowerPC] Treat 'Z' inline asm constraint as a true memory constraint
We currently emit incorrect codegen for this constraint because we set it as a constraint that allows registers. This will cause the value to be copied to the stack and that address to be passed as the address. This is not what we want. Fixes: https://bugs.llvm.org/show_bug.cgi?id=42762 Differential revision: https://reviews.llvm.org/D77542
1 parent 1a493b0 commit aede24e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

clang/lib/Basic/Targets/PPC.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,12 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
276276
break;
277277
case 'Q': // Memory operand that is an offset from a register (it is
278278
// usually better to use `m' or `es' in asm statements)
279+
Info.setAllowsRegister();
280+
LLVM_FALLTHROUGH;
279281
case 'Z': // Memory operand that is an indexed or indirect from a
280282
// register (it is usually better to use `m' or `es' in
281283
// asm statements)
282284
Info.setAllowsMemory();
283-
Info.setAllowsRegister();
284285
break;
285286
case 'R': // AIX TOC entry
286287
case 'a': // Address operand that is an indexed or indirect from a

clang/test/CodeGen/ppc64-inline-asm.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,16 @@ double test_fmax(double x, double y) {
3737
// CHECK-LABEL: double @test_fmax(double %x, double %y)
3838
// CHECK: call double asm "xsmaxdp ${0:x}, ${1:x}, ${2:x}", "=^ws,^ws,^ws"(double %x, double %y)
3939
}
40+
41+
void testZ(void *addr) {
42+
asm volatile ("dcbz %y0\n" :: "Z"(*(unsigned char *)addr) : "memory");
43+
// CHECK-LABEL: void @testZ(i8* %addr)
44+
// CHECK: call void asm sideeffect "dcbz ${0:y}\0A", "*Z,~{memory}"(i8* %addr)
45+
}
46+
47+
void testZwOff(void *addr, long long off) {
48+
asm volatile ("dcbz %y0\n" :: "Z"(*(unsigned char *)(addr + off)) : "memory");
49+
// CHECK-LABEL: void @testZwOff(i8* %addr, i64 %off)
50+
// CHECK: %[[VAL:[^ ]+]] = getelementptr i8, i8* %addr, i64 %off
51+
// CHECK: call void asm sideeffect "dcbz ${0:y}\0A", "*Z,~{memory}"(i8* %[[VAL]])
52+
}

0 commit comments

Comments
 (0)