Issue 243534
Summary [PowerPC] "Impossible reg-to-reg copy" with a register variable in ctr used as an inline asm operand
Labels new issue
Assignees
Reporter mu-mu-mu
    On PowerPC, clang accepts a local register variable in the count register used as an inline asm operand, but an assertions build hits `llvm_unreachable("Impossible reg-to-reg copy")` in `PPCInstrInfo::copyPhysReg`. 

### Reproducer

```c
long f(long v)
{
 register long x __asm__("ctr") = v;
    __asm__ volatile("" : "+c"(x));
    return x;
}
```

```console
$ clang --target=powerpc64le-linux-gnu -c test.c
```

### Actual behavior

Trunk (c0005dfe81fe) with assertions:

```console
$ clang --version
clang version 24.0.0git
Build config: +assertions
```

```console
$ clang --target=powerpc64le-linux-gnu -c test.c
Impossible reg-to-reg copy
UNREACHABLE executed at llvm/lib/Target/PowerPC/PPCInstrInfo.cpp:1897!
...
4.	Running pass 'Post-RA pseudo instruction expansion pass' on function '@f'
...
llvm::TargetInstrInfo::lowerCopy(llvm::MachineInstr*) const
```

test-f23516.c

```c
# 1 "<built-in>"
# 1 "test.c"
long f(long v)
{
    register long x __asm__("ctr") = v;
    __asm__ volatile("" : "+c"(x));
    return x;
}
```

test-f23516.sh

```sh
# Crash reproducer for clang version 24.0.0git
# Driver args: "--target=powerpc64le-linux-gnu" "-c" "test.c" "-o" "/dev/null"
# Original command: "/opt/clang-trunk/bin/clang-24" "-cc1" "-triple" "powerpc64le-unknown-linux-gnu" "-emit-obj" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "test.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "ppc64le" "-mfloat-abi" "hard" "-target-abi" "elfv2" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/w" "-fcoverage-compilation-dir=/w" "-resource-dir" "/opt/clang-trunk/lib/clang/24" "-internal-isystem" "/opt/clang-trunk/lib/clang/24/include/ppc_wrappers" "-internal-isystem" "/opt/clang-trunk/lib/clang/24/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc-cross/powerpc64le-linux-gnu/16/../../../../powerpc64le-linux-gnu/include" "-internal-externc-isystem" "/usr/include/powerpc64le-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-ferror-limit" "19" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-faddrsig" "-fdwarf2-cfi-asm" "-o" "/dev/null" "-x" "c" "test.c"
 "/opt/clang-trunk/bin/clang-24" "-cc1" "-triple" "powerpc64le-unknown-linux-gnu" "-emit-obj" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "test.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "ppc64le" "-mfloat-abi" "hard" "-target-abi" "elfv2" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/w" "-fcoverage-compilation-dir=/w" "-ferror-limit" "19" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-faddrsig" "-fdwarf2-cfi-asm" "-x" "c" "test-f23516.c"
```

Without assertions (godbolt clang trunk, -O2 -S), clang emits `dmmr`, an unrelated Dense Math instruction:

```
f:
 dmmr ctr, 3
        dmmr 3, ctr
        blr
```

### Expected behavior

clang compiles it without crashing, or rejects it with an error if register variables in ctr are not supported.

clang (assertions trunk): https://godbolt.org/z/KdbGvsxz1

clang (trunk): https://godbolt.org/z/9jzxsqj9P

Found by automated testing.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to