This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Fold uadd.sat(a, b) == 0 and usub.sat(a, b) == 0
ClosedPublic

Authored by nikic on Oct 20 2019, 12:53 PM.

Details

Summary

This adds folds for comparing uadd.sat/usub.sat with zero:

  • uadd.sat(a, b) == 0 => a == 0 && b == 0 => (a | b) == 0
  • usub.sat(a, b) == 0 => a <= b

And inverted forms for !=.

Diff Detail

Event Timeline

nikic created this revision.Oct 20 2019, 12:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 20 2019, 12:53 PM
lebedev.ri accepted this revision.Oct 20 2019, 1:06 PM
----------------------------------------
Name: uadd.sat(a, b) == 0  ->  (a | b) == 0
  %o0 = uadd_sat i8 %x, %y
  %r = icmp eq i8 %o0, 0
  ret i1 %r
=>
  %n0 = or i8 %x, %y
  %r = icmp eq i8 %n0, 0
  ret i1 %r
  %o0 = uadd_sat i8 %x, %y

Done: 1
Optimization is correct!

----------------------------------------
Name: uadd.sat(a, b) != 0  ->  (a | b) != 0
  %o0 = uadd_sat i8 %x, %y
  %r = icmp ne i8 %o0, 0
  ret i1 %r
=>
  %n0 = or i8 %x, %y
  %r = icmp ne i8 %n0, 0
  ret i1 %r
  %o0 = uadd_sat i8 %x, %y

Done: 1
Optimization is correct!

----------------------------------------
Name: usub.sat(a, b) == 0  ->  a <= b
  %o0 = usub_sat i8 %x, %y
  %r = icmp eq i8 %o0, 0
  ret i1 %r
=>
  %r = icmp ule i8 %x, %y
  ret i1 %r
  %o0 = usub_sat i8 %x, %y

Done: 1
Optimization is correct!

----------------------------------------
Name: usub.sat(a, b) != 0  ->  a > b
  %o0 = usub_sat i8 %x, %y
  %r = icmp ne i8 %o0, 0
  ret i1 %r
=>
  %r = icmp ugt i8 %x, %y
  ret i1 %r
  %o0 = usub_sat i8 %x, %y

Done: 1
Optimization is correct!

LG

This revision is now accepted and ready to land.Oct 20 2019, 1:06 PM
This revision was automatically updated to reflect the committed changes.