Issue |
153781
|
Summary |
Unprofitable use of th.ext insn for clamping
|
Labels |
new issue
|
Assignees |
|
Reporter |
christian-herber-nxp
|
This sequence, as seen in https://github.com/embench/embench-iot/blob/master/src/picojpeg/libpicojpeg.c,
```
#include <stdint.h>
uint8_t clamp (int16_t s)
{
if ((uint16_t) s > 255U)
{
if (s < 0)
return 0;
else if (s > 255)
return 255;
}
return (uint8_t) s;
}
```
Leads to suboptimal assembly when compiling for the xtheadbb: https://godbolt.org/z/e7o1dseKW
-march=rv32gc_xtheadbb:
```
clamp(short):
li a1, 255
bgeu a1, a0, .LBB0_2
srli a0, a0, 31
not a0, a0
th.ext a0, a0, 0, 0
.LBB0_2:
zext.b a0, a0
ret
```
-march=rv32gc:
```
clamp(short):
li a1, 255
bgeu a1, a0, .LBB0_2
srli a0, a0, 31
addi a0, a0, -1
.LBB0_2:
zext.b a0, a0
ret
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs