https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62262
Bug ID: 62262 Summary: aarch64 gcc generates invalid assembler Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: carrot at google dot com Target: aarch64 Compile following source code with options -fprofile-use -O2 static inline int CLZ(int mask) { return mask ? __builtin_clz(mask) : 32; } int foo(int value) { if (value == 0) return 0; int bias = CLZ(value); value >>= bias; int zeros = CLZ(value << 1); value <<= zeros; int packed = (unsigned)(value << 9) >> 9; return packed; } Without any actual profiling data, trunk gcc generates /tmp/cctLq1F0.s: Assembler messages: /tmp/cctLq1F0.s:20: Error: immediate value out of range 0 to 31 at operand 3 -- `ubfiz w0,w2,32,23' The generated assembler code is: foo: cbz w0, .L4 clz w1, w0 asr w2, w0, w1 adds w0, w2, w2 beq .L3 clz w3, w0 lsl w4, w2, w3 and w0, w4, 8388607 ret .L3: ubfiz w0, w2, 32, 23 // Wrong code ret .L4: mov w0, 0 ret 4.9 gcc generates the same error.