LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 42576 - aarch64: -march=armv8-a produces armv8.2 'bfc' instruction
Summary: aarch64: -march=armv8-a produces armv8.2 'bfc' instruction
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: C (show other bugs)
Version: trunk
Hardware: PC Linux
: P enhancement
Assignee: Nick Desaulniers
URL:
Keywords:
Depends on:
Blocks: 4068 release-9.0.1
  Show dependency tree
 
Reported: 2019-07-11 01:41 PDT by Arnd Bergmann
Modified: 2019-11-25 10:48 PST (History)
10 users (show)

See Also:
Fixed By Commit(s): r373655 62a16ca


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Arnd Bergmann 2019-07-11 01:41:59 PDT
Building arm64 linux randconfig kernels, I came across this assembler error:

/tmp/sdma_v4_0-f95fd3.s: Assembler messages:
/tmp/sdma_v4_0-f95fd3.s:44: Error: selected processor does not support `bfc w0,#1,#5'

I reduced the test case to

int a, b, c;
int __order_base_2() { return a > 1 ? __builtin_constant_p(a) ?: b : 0; }
int sdma_v4_0_rb_cntl(int p1) {
  int d = c ?: __order_base_2();
  p1 = (p1 & ~0x0000003EL) | (62 & (d << 1));
  return p1;
}
$ clang-8  --prefix=/home/arnd/cross/x86_64/gcc-8.1.0-nolibc/aarch64-linux/bin/ -no-integrated-as -O2 sdma_v4_0.i --target=aarch64-linux -S -o- -march=armv8.1-a

https://godbolt.org/z/8Gcjl9 shows the 'bfc' instruction being generated, but not the error message as it is unable to call the external assembler correctly.

According to https://sourceware.org/ml/binutils/2015-11/msg00221.html, the 'bfc' instruction is only valid in armv8.2 or higher but llvm uses it for any armv8 version.
Comment 1 Tim Northover 2019-07-11 02:58:04 PDT
It's an alias so the underlying instruction exists in v8.0. Gating it on the architecture is weird.

We might want to change how we print it when targeting < v8.2, but I'm pretty disinclined to diagnose an error in our own assembler.
Comment 2 Nick Desaulniers 2019-07-11 11:05:35 PDT
> -march=armv8.1-a

Orthogonal, Arnd, is there a config that sets that specific march flag?

> but I'm pretty disinclined to diagnose an error in our own assembler.


Would be a bug in AsmPrinter?
Comment 3 Tim Northover 2019-07-11 11:09:44 PDT
> Would be a bug in AsmPrinter?

In LLVM terms, if the current behaviour is considered a bug, it would be fixed in what's called the "InstPrinter" in lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp.

There's specific C++ code to detect and print "bfc", which could be modified to only do that when targeting v8.2a or above.

How's that for a carefully hedged reply!
Comment 4 Arnd Bergmann 2019-07-11 14:25:18 PDT
(In reply to Nick Desaulniers from comment #2)
> > -march=armv8.1-a
> 
> Orthogonal, Arnd, is there a config that sets that specific march flag?

I don't think so, I added that to the test case for clarification.

If I remember correctly, the kernel is always built for armv8-a rather than a later version, to provide the best compatibility with existing CPUs (most of what is in production today is still armv8-a, not 8.1 or 8.2).

(In reply to Tim Northover from comment #1)
> It's an alias so the underlying instruction exists in v8.0. Gating it on the
> architecture is weird.
> 
> We might want to change how we print it when targeting < v8.2, but I'm
> pretty disinclined to diagnose an error in our own assembler.

Makes sense. As I understand section A1.7.4 in the ARM ARM, an assembler is only required to understand bfc when targetting v8.2, but it is may choose to interpret it correctly anyway.
Comment 5 Tim Northover 2019-07-11 14:26:43 PDT
> Makes sense. As I understand section A1.7.4 in the ARM ARM, an assembler is only required to understand bfc when targetting v8.2, but it is may choose to interpret it correctly anyway.

Nicely put! I wish I'd thought of that when writing my reply.
Comment 6 Arnd Bergmann 2019-10-02 04:57:55 PDT
I see the bug is still present in clang-9 and clang-10, so I'm resending my workaround for the kernel.
Comment 7 Nick Desaulniers 2019-10-02 13:40:59 PDT
https://reviews.llvm.org/D68356
Comment 8 Nick Desaulniers 2019-10-03 13:14:10 PDT
https://reviews.llvm.org/rL373655
Comment 9 Tom Stellard 2019-10-04 09:22:39 PDT
(In reply to Nick Desaulniers from comment #8)
> https://reviews.llvm.org/rL373655

Tim, is this OK to merge to the release/9.x branch?
Comment 10 Tim Northover 2019-10-04 10:24:05 PDT
I think so.
Comment 11 Eli Friedman 2019-10-07 12:35:14 PDT
(Reopening to track 9.0.1.)
Comment 12 Tom Stellard 2019-11-25 10:48:04 PST
Merged: 62a16ca