The constants come through as add %x, -C, not a sub as would be expected. They need some extra matchers to canonicalise them towards usub_sat.
---------------------------------------- Optimization: Forwards Precondition: true %cmp = icmp ugt i32 %a, 10 %sub = add i32 %a, -10 %sel = select i1 %cmp, i32 %sub, i32 0 => %sel = usub_sat %a, 10 Done: 1 Optimization is correct! ---------------------------------------- Optimization: Backwards Precondition: true %cmp = icmp ult i32 %a, 2 %sub = add i32 %a, -2 %sel = select i1 %cmp, i32 %sub, i32 0 => %x = usub_sat 2, %a %sel = sub 0, %x Done: 1 Optimization is correct!
I'm having doubt about the comment.
If b < a, then b - a will wrap, and we'll return wrapped result.
And if b >= a, then b - a will not wrap, but we will saturate to 0.
What am i missing?