Unoptimal code with flags output and "asm goto"
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The following testcase
```c
void foo (void);
void bar (void);
void qux (void)
{
_Bool err;
asm goto ("#" :"=@ccz" (err) : : : lab);
if (err)
bar ();
return;
lab:
if (err)
foo ();
return;
}
```
compiles with `clang -O2` to:
```asm
# %bb.0:
#APP
#
#NO_APP
sete %al
# %bb.1:
testb %al, %al
je .LBB0_4
# %bb.2:
jmp bar # TAILCALL
.LBB0_3: # Inline asm indirect target
# Label of block must be emitted
je foo # TAILCALL
.LBB0_4:
retq
```
Please note unnecessary `sete %al / testb %al,%al / je ...` sequence that could be substituted with simple `jne ...`, as is the case after .LBB0_3 inline asm indirect target label.
Contributor guide
Research direction
Start by reproducing the supplied C testcase with clang -O2 and comparing its assembly output. Trace the compiler handling of asm goto with an output flag and an indirect target; done means the redundant sete/testb/conditional-branch sequence is removed without changing either control-flow path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100