Page MenuHomePhabricator

[InstSimplify] simplify abs if operand is known non-negative
ClosedPublic

Authored by spatel on Fri, Jul 31, 1:48 PM.

Details

Summary

abs() should be rare enough that using value tracking is not going to be a compile-time cost burden, so use it to reduce a variety of potential patterns. We do this in DAGCombiner too.

Diff Detail

Event Timeline

spatel created this revision.Fri, Jul 31, 1:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptFri, Jul 31, 1:48 PM
spatel requested review of this revision.Fri, Jul 31, 1:48 PM
nikic added a comment.Fri, Jul 31, 2:33 PM

Yes, we should be fine compile-time wise. The icmp + select representation of abs implicitly did this as well, because we fold comparisons against zero more aggressively than others.

llvm/lib/Analysis/InstructionSimplify.cpp
5260

We should also pass through Q.AC, Q.CxtI, Q.DT.

spatel updated this revision to Diff 282340.Fri, Jul 31, 3:46 PM

Patch updated:
Pass in more info from the SimplifyQuery to ValueTracking.
Not sure what it takes to show the benefit, so no test diffs, but if there are suggestions, let me know.

nikic accepted this revision.Sat, Aug 1, 12:49 AM

LG

Patch updated:
Pass in more info from the SimplifyQuery to ValueTracking.
Not sure what it takes to show the benefit, so no test diffs, but if there are suggestions, let me know.

Something like assume(x >= 0); abs(x) should do it.

This revision is now accepted and ready to land.Sat, Aug 1, 12:49 AM