Page MenuHomePhabricator

Constant folding and instcombine for saturating subs
AbandonedPublic

Authored by nikic on Nov 8 2018, 2:01 PM.

Details

Summary

This is a continuation of D54237 for the subtraction case. The following simplifications / folds have been implemented:

  • Constant folding sat(C1 - C2) -> C3
  • sat(X - 0) -> X
  • sat(X - X) -> 0
  • sat(X - undef) -> 0
  • sat(undef - X) -> 0
  • sat(0 usub X) -> 0
  • sat(X usub MAX) -> 0
  • sat(sat(X - C1) - C2) -> sat(X + C3) where legal
  • sat(X1 - X2) -> sub nuw/nsw where possible

I've also changed the computeOverflowForUnsignedSub() implementation to return AlwaysOverflows results, for parity with the computeOverflowForUnsignedAdd() implementation. The results were weirdly asymmetric previously.

Diff Detail

Event Timeline

nikic created this revision.Nov 8 2018, 2:01 PM
rkruppe added a subscriber: rkruppe.Nov 8 2018, 2:32 PM
nikic updated this revision to Diff 173290.Nov 9 2018, 2:38 AM
nikic edited the summary of this revision. (Show Details)

Simplify sat(X - undef) -> X for symmetry with the add simplification.

nikic updated this revision to Diff 173550.Nov 11 2018, 2:32 AM
nikic edited the summary of this revision. (Show Details)

Rebase over APInt patch, implement new undef folds with zero result.

Please can you add vector constant folding tests + support?

RKSimon accepted this revision.Nov 14 2018, 6:51 AM

LGTM - happy for vector support to be added as a follow up patch

This revision is now accepted and ready to land.Nov 14 2018, 6:51 AM
nikic abandoned this revision.Nov 18 2018, 7:28 AM

Abandoning in favor of the patch series listed in https://reviews.llvm.org/D54237#1298642.