This is an archive of the discontinued LLVM Phabricator instance.

[SCEVExpander] Discount cost of umin(1, x) expressions
AbandonedPublic

Authored by reames on Jun 30 2021, 9:51 AM.

Details

Summary

umin(1, x) reduces to checking if x != 0 as the expression can only be zero if x == 0. InstCombine has been taught to turn the umin form into the zext of icmp form; this patch adjusts the cost model used for determining if an expression is "high cost" to apply discount the same case.

This is was found while working on a variant of what would eventually become D105216. It has the effect of allowing LFTR more often when we use the ceiling expansion. However, I have not been able to find a way to test it on it's own. I'm tempted to land it without tests, but maybe a reviewer has a better idea?

Diff Detail

Event Timeline

reames created this revision.Jun 30 2021, 9:51 AM
reames requested review of this revision.Jun 30 2021, 9:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2021, 9:51 AM
reames planned changes to this revision.Jun 30 2021, 10:35 AM

For future self:

  • and reduction trick does not hold when A and B are both non-zero, but with different bits set.
  • the original umin(a,1) trick still holds, it's the extension to multiple operands which was wrong
reames updated this revision to Diff 355928.Jul 1 2021, 10:10 AM

Rely on instcombine, and remove wrong code.

reames updated this revision to Diff 357955.Jul 12 2021, 8:44 AM
reames retitled this revision from [WIP][SCEVExpander] Discount cost of umin(x,1) expressions to [SCEVExpander] Discount cost of umin(1, x) expressions.
reames edited the summary of this revision. (Show Details)
reames added reviewers: efriedma, fhahn.
reames set the repository for this revision to rG LLVM Github Monorepo.

Can we write tests for this, now that all the overflow stuff has landed?

fhahn added a comment.Aug 13 2021, 1:28 AM

This looks good to me. It would be good to have a test though.

fhahn added a comment.Aug 13 2021, 1:29 AM

(Let me try if I can get this to trigger so we can extract a test)

fhahn added a comment.Aug 16 2021, 6:12 AM

(Let me try if I can get this to trigger so we can extract a test)

Hm I couldn't get this triggered on MultiSource/SPEC2006/SPEC2017 with -O3 on X86. Philip, do you have any thoughts if a different combination of flags may make this trigger in C/C++?

reames abandoned this revision.Aug 17 2021, 9:15 AM

Abandoning this for now. This came up in an alternate approach to the overflow during BTC computation issue, and I separated it out. It doesn't appear to matter with the current approach, so I'll defer this until it does. I think the patch is correct, it just doesn't have a strong motivation or test right now.