llvm / llvm/llvm-project

Miss optimization for ARM Code

Open
#196,488 2 comments 1 reaction 0 assignees View on GitHub
backend:ARM llvm:optimizations missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Given an example:
```cpp
auto f(unsigned a, bool b)
{
return a << (b ? 0 : 16);
}
```

Use `-march=armv7-m -O3` option to compile the code. The ARM GCC generates:
```asm
f(unsigned int, bool):
eor r1, r1, #1
lsls r1, r1, #4
lsls r0, r0, r1
bx lr
```

But clang generates:
```asm
f(unsigned int, bool):
cmp r1, #0
mov.w r1, #16
it ne
movne r1, #0
lsls r0, r1
bx lr
```

Here is [the link](https://gcc.godbolt.org/z/rYjzdE7fK) to godbolt.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.