[PATCH] D124435: [X86] Always extend the integer parameters in callee

LiuChen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 26 06:19:14 PDT 2022


LiuChen3 added inline comments.


================
Comment at: clang/test/CodeGen/X86/integer_argument_passing.c:2
+// RUN: %clang_cc1 -O2 -triple -x86_64-linux-gnu %s -emit-llvm -o - | FileCheck %s --check-prefixes=EXTEND,CHECK
+// RUN: %clang_cc1 -O2 -triple -i386-linux-gnu %s -emit-llvm -o - | FileCheck %s --check-prefixes=EXTEND,CHECK
+// RUN: %clang_cc1 -O2 -triple -i386-pc-win32 %s -emit-llvm -o - | FileCheck %s --check-prefixes=EXTEND,CHECK
----------------
pengfei wrote:
> pengfei wrote:
> > LiuChen3 wrote:
> > > pengfei wrote:
> > > > Maybe we can remove the tests for i386 given it's only for 64 bits ABI?
> > > According to the meaning of `ConservativeExtend`, I think the 32bit ABI needs to be modified as well:
> > > https://godbolt.org/z/W1Ma1T3f3
> > > The dump of currently clang-cl:
> > > ```
> > > _square:
> > >         movb    4(%esp), %al
> > >         mulb    %al
> > >         mulb    8(%esp)
> > >         retl
> > > 
> > >         .def    _baz;
> > >         .scl    2;
> > >         .type   32;
> > >         .endef
> > >         .section        .text,"xr",one_only,_baz
> > >         .globl  _baz
> > >         .p2align        4, 0x90
> > > _baz:
> > >         movswl  4(%esp), %eax
> > >         pushl   %eax
> > >         calll   _bar
> > >         addl    $4, %esp
> > >         retl
> > > ```
> > > Of course with this patch the behavior of clang-cl is still different from cl.exe, but I think it fits the meaning of `ConservativeExtend`.
> > My point was, i386 is passing arguments by stack. The extensions don't make sense under the circumstances. That's what I understood the comments in above test 2007-06-18-SextAttrAggregate.c
> Oh, seems I misunderstood it. The stack still needs extensions since it's aligned to 4 bytes. But from the above output, the clang-cl is wrong, because it extends on caller which MSVC extends on callee. So back the another question, we should change for Windows too, right?
I just change the behavior of win32. Windows 64 will always do the extensions in callee. I didn't support `ConservativeExtend` for win64. The dump IR of currently clang-cl is:
```
define dso_local i8 @square(i8 noundef %a, i8 noundef %b) local_unnamed_addr #0 {
...
}

  %call = tail call i32 @bar(i16 noundef %conv) #3
...
}

define dso_local i32 @baz(i32 noundef %num) local_unnamed_addr #1 {
...
  %call = tail call i32 @bar(i16 noundef %conv) #3
...
}
```
I think maybe we don't need to do the extension both in caller and callee for WIN64?  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124435



More information about the cfe-commits mailing list