[PATCH] D125285: [BuildLibCalls] infer inreg param attrs from NumRegisterParameters

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 10 13:41:46 PDT 2022


nickdesaulniers marked an inline comment as done.
nickdesaulniers added inline comments.


================
Comment at: llvm/test/Transforms/InstCombine/simplify-libcalls-inreg.ll:47
+
+; CHECK:     declare noundef i32 @sprintf(ptr inreg noalias nocapture noundef writeonly, ptr inreg nocapture noundef readonly, ...)
+; CHECK-NOT: declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...)
----------------
efriedma wrote:
> Is this inreg marking correct for sprintf?
> 
> Looking at clang output, we actually add inreg markings, but the backend ignores them.  I guess if we do the same thing, that's fine?
> Is this inreg marking correct for sprintf?

sprintf takes two ptr params, then the rest are variadic; yes?

> I guess if we do the same thing, that's fine?

I think so:

```
// /tmp/sprintf.c
#include <stdio.h>

char a [20];
char b [20];

int x(void) {
  return sprintf(a, b, "hello");
}
```
```
$ gcc -m32 -mregparm=3 -S -o - -O2 /tmp/sprintf.c -fno-pic -fno-asynchronous-unwind-tables
...
x:
        subl    $16, %esp
        pushl   $.LC0
        pushl   $b
        pushl   $a
        call    sprintf
        addl    $28, %esp
        ret
$ clang -m32 -mregparm=3 -S -o - -O2 /tmp/sprintf.c -fno-pic -fno-asynchronous-unwind-tables
...
x:                                      # @x
# %bb.0:                                # %entry
        subl    $16, %esp
        pushl   $.L.str
        pushl   $b
        pushl   $a
        calll   sprintf
        addl    $28, %esp
        retl
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125285/new/

https://reviews.llvm.org/D125285



More information about the llvm-commits mailing list