This is a fork of the LLVM project. The code in branch my66000 supports Mitch Alsup's MY66000. The code in branch mcore supports the Motorola MCore.
2
stars
2
forks
source link
Optimize select of constants that differ by one. #46
Closed
bagel99 closed 1 year ago
// The following code could be better optimized.
long len2; long foo1() { if (len2 < 0) return 5; return 6; }
long foo2() { if (len2 < 0) return 6; return 5; }
Currently produces: foo1: ldd r1,[ip,len2] cmp r1,r1,#0 sra r1,r1,<1:4> mov r2,#5 mux r1,r1,r2,#6 ret foo2: ldd r1,[ip,len2] cmp r1,r1,#0 sra r1,r1,<1:4> mov r2,#6 mux r1,r1,r2,#5 ret
Better code would be: foo1: ldd r1,[ip,len2] sra r1,r1,<0:63> add r1,r1,#6 ret foo2: ldd r1,[ip,len2] srl r1,r1,<0:63> add r1,r1,#5 ret