Closed
Description
Alive2 proof: https://alive2.llvm.org/ce/z/V82mt-
Description:
long src(long a, long b) {
if(a < b){
return max(b, a + 1);
}else{
return 0;
}
}
can be folded to:
long tgt(long a, long b) {
if(a < b){
return b;
}else{
return 0;
}
}
Similarly, it also applies to other cases like a > b
, min(b, a + 1)
and so on.
Real-world motivation
This snippet of IR is derived from redis/src/db.c@readGetKeys (after O3 pipeline).
The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, see also:https://godbolt.org/z/YaEYnedYW
Let me know if you can confirm that it's an optimization opportunity, thanks.