bwendling wrote:

> This generally looks reasonable to me, with two main concerns:
> 
> * Don't we need to handle callbr as well?

Probably, but I want to do that in a follow-up commit because it's likely to be 
more complex.

> * It seems like the semantics of `"rm"` input constraints get changed by the 
> prepare pass without any indication in the IR.

Could you give an example?

> Another issue I found is that this code:
> 
> ```
> unsigned test(unsigned v) {
>   unsigned ret;
>   __asm__("movl %1, %0" : "=rm"(ret) : "rm"(v));
>   return ret;
> }
> ```
> 
> Omits the inline asm completely at `-O0` now. I haven't looked deeply, but I 
> suspect the reason is that the inline asm was originally marked 
> `memory(read)`, which is no longer true after the transform.

This is something that Clang isn't able to handle currently even at `-O2`:

```
$ clang -o - -O0 -S ~/llvm/a.c -m64
        .text
        .file   "a.c"
        .globl  test                            # -- Begin function test
        .p2align        4, 0x90
        .type   test,@function
test:                                   # @test
        .cfi_startproc
# %bb.0:
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset %rbp, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register %rbp
        movl    %edi, -4(%rbp)
        movl    -4(%rbp), %eax
        movl    %eax, -12(%rbp)
        #APP
/home/morbo/llvm/a.c:3:11: error: invalid operand for instruction
    3 |   __asm__("movl %1, %0" : "=rm"(ret) : "rm"(v));
      |           ^
<inline asm>:1:18: note: instantiated into assembly here
    1 |         movl -12(%rbp), -8(%rbp)
      |                         ^~~~~~~~
        #NO_APP
        movl    -8(%rbp), %eax
        popq    %rbp
        .cfi_def_cfa %rsp, 8
        retq
.Lfunc_end0:
        .size   test, .Lfunc_end0-test
        .cfi_endproc
                                        # -- End function
        .ident  "Debian clang version 19.1.7 (10.1+build1)"
        .section        ".note.GNU-stack","",@progbits
        .addrsig
1 error generated.

$ clang -o - -O2 -S ~/llvm/a.c
        .text
        .file   "a.c"
        .globl  test                            # -- Begin function test
        .p2align        4, 0x90
        .type   test,@function
test:                                   # @test
        .cfi_startproc
# %bb.0:
        movl    %edi, -8(%rsp)
        #APP
/home/morbo/llvm/a.c:3:11: error: invalid operand for instruction
    3 |   __asm__("movl %1, %0" : "=rm"(ret) : "rm"(v));
      |           ^
<inline asm>:1:17: note: instantiated into assembly here
    1 |         movl -8(%rsp), -4(%rsp)
      |                        ^~~~~~~~
        #NO_APP
        movl    -4(%rsp), %eax
        retq
.Lfunc_end0:
        .size   test, .Lfunc_end0-test
        .cfi_endproc
                                        # -- End function
        .ident  "Debian clang version 19.1.7 (10.1+build1)"
        .section        ".note.GNU-stack","",@progbits
        .addrsig
1 error generated.
```

This is because the `mov` can't move between memory addresses. I'm not sure why 
my change omits the assembly entirely though. I'll look into it.

https://github.com/llvm/llvm-project/pull/181973
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to