llvm / llvm/llvm-project

[InstCombine] failed to fold (a & b) != b ? (a | b) : a to (a | b)

Open
#207,909 5 comments 0 reactions 0 assignees View on GitHub
llvm:instcombine missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```c
int f(int a, int b) { return (a & b) != b ? (a | b) : a; }

int f0(int a, int b) { return a | b; }
```
```asm
f(int, int):
andn eax, edi, esi
cmovne eax, esi
or eax, edi
ret

f0(int, int):
mov eax, edi
or eax, esi
ret
```
https://godbolt.org/z/sK6cnsbTc

Contributor guide

Open the contributing guide

Research direction

Reproduce the C example and inspect the InstCombine entry point responsible for simplifying the conditional expression. Compare the generated assembly with f0 and verify that the expression folds to the equivalent a | b form without the extra conditional sequence.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.