[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <679c0129-ca59-47a4-aa83-f79ec166951a@app.fastmail.com>
Date: Tue, 11 Oct 2022 13:01:22 +0200
From: "Arnd Bergmann" <arnd@...nel.org>
To: "Nick Desaulniers" <ndesaulniers@...gle.com>,
"Russell King" <linux@...linux.org.uk>
Cc: "Tom Rix" <trix@...hat.com>, linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org, llvm@...ts.linux.dev,
"Miguel Ojeda" <ojeda@...nel.org>,
"Ard Biesheuvel" <ardb@...nel.org>, "Gary Guo" <gary@...yguo.net>,
"Craig Topper" <craig.topper@...ive.com>,
"Philip Reames" <listmail@...lipreames.com>, jh@...user.us,
"Nathan Chancellor" <nathan@...nel.org>
Subject: Re: [PATCH] ARM: NWFPE: avoid compiler-generated __aeabi_uldivmod
On Tue, Oct 11, 2022, at 12:53 AM, Nick Desaulniers wrote:
> clang-15's ability to elide loops completely became more aggressive when
> it can deduce how a variable is being updated in a loop. Counting down
> one variable by an increment of another can be replaced by a modulo
> operation.
>
> For 64b variables on 32b ARM EABI targets, this can result in the
> compiler generating calls to __aeabi_uldivmod, which it does for a do
> while loop in float64_rem().
>
> For the kernel, we'd generally prefer that developers not open code 64b
> division via binary / operators and instead use the more explicit
> helpers from div64.h. On arm-linux-gnuabi targets, failure to do so can
> result in linkage failures due to undefined references to
> __aeabi_uldivmod().
>
> While developers can avoid open coding divisions on 64b variables, the
> compiler doesn't know that the Linux kernel has a partial implementation
> of a compiler runtime (--rtlib) to enforce this convention.
>
> It's also undecidable for the compiler whether the code in question
> would be faster to execute the loop vs elide it and do the 64b division.
>
> While I actively avoid using the internal -mllvm command line flags, I
> think we get better code than using barrier() here, which will force
> reloads+spills in the loop for all toolchains.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1666
> Reported-by: Nathan Chancellor <nathan@...nel.org>
> Signed-off-by: Nick Desaulniers <ndesaulniers@...gle.com>
Works for me,
Reviewed-by: Arnd Bergmann <arnd@...db.de>
I would have been fine with disallowing NWFPE for clang, or with
adding a barrier in the loop as well, i.e. any approach that
doesn't cause invalid behavior or a maintenance burden, given that
there is probably nobody that actually needs nwfpe on a clang built
kernel.
Arnd
Powered by blists - more mailing lists