This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by spatel on Jul 31 2020, 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.Jul 31 2020, 1:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 31 2020, 1:48 PM
spatel requested review of this revision.Jul 31 2020, 1:48 PM
nikic added a comment.Jul 31 2020, 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.Jul 31 2020, 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.Aug 1 2020, 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.Aug 1 2020, 12:49 AM