[PATCH] D120329: [SelectionDAG] Emit calls to __divei4 and friends for division/remainder of large integers

Phoebe Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 14 22:20:12 PDT 2022


pengfei added inline comments.


================
Comment at: llvm/test/CodeGen/X86/udivmodei5.ll:5
+
+define i129 @udiv129(i129 %a, i129 %b) {
+; X86-LABEL: udiv129:
----------------
aaron.ballman wrote:
> pengfei wrote:
> > LuoYuanke wrote:
> > > I'm not sure it is legal to pass i129. It seems front-end would pass i129 by value. However it is not related to this patch.
> > > 
> > > 
> > > ```
> > > [clang]$ cat t.c
> > > _BitInt(129) foo(_BitInt(129) a) {
> > >   return a++;
> > > }
> > > [clang]$
> > > [clang]$ clang -S t.c -emit-llvm -O2
> > > [clang]$ cat t.ll
> > > ; ModuleID = 't.c'
> > > source_filename = "t.c"
> > > target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
> > > target triple = "x86_64-unknown-linux-gnu"
> > > 
> > > ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn uwtable
> > > define dso_local void @foo(i129* noalias nocapture writeonly sret(i129) align 8 %agg.result, i129* nocapture noundef readonly byval(i129) align 8 %0) local_unnamed_addr #0 {
> > > entry:
> > >   %a = load i129, i129* %0, align 8, !tbaa !3
> > >   store i129 %a, i129* %agg.result, align 8, !tbaa !3
> > >   ret void
> > > }
> > > 
> > > ```
> > I think we'd better to avoid passing / returning `i129` type in tests, especially the returning.
> > https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/X86/X86CallingConv.td#L221-L222
> > The comments said returning more than two registers is out of the ABI scope. What's more, unlike the passing arguments, returning just has 3 usable registers and cannot use stack. So it will always crash if we want to return a type larger than `i192`.
> > So it will always crash if we want to return a type larger than i192.
> 
> This seems like a bug we'd need to fix, yes?
Sorry, my mistake. It won't crash https://godbolt.org/z/f6b66xcfe. It turns out only type `i129` ~ `i192` has dubious behavior.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120329



More information about the llvm-commits mailing list