Page MenuHomePhabricator

[InstCombine] Demand bits of UMAX

Authored by dmgreen on Oct 9 2018, 12:00 PM.



This is part of of D52508. It uses the demand bits of umax(A, C) to prove we use just A, so long as:
"The lowest non-zero bit of DemandMask is higher than the highest non-zero bit of C"

Conceptually, this works because:
if A > C, we pick A. No big deal.
if A < C then all the demanded bits of A == demanded bits of C, so we can pick either and get the same result. So we pick A.

Diff Detail


Event Timeline

dmgreen created this revision.Oct 9 2018, 12:00 PM

Unfortunately I don't have a great way to prove this with Alive, as I don't believe it can do clz/ctz's in preconditions.

Seems to work fine

Ah, I must have been looking at the wrong bit of code. Thanks!

In that case,

lebedev.ri added inline comments.Oct 9 2018, 12:34 PM
326–327 ↗(On Diff #168817)

I wonder if it's any cleaner to write this as

C->countLeadingZeros() + DemandedMask.countTrailingZeros() => C->getBitWidth()
I.e. that leading zeros (in high bits), and trailing zeros (in low bits) overlap/touch.

craig.topper added inline comments.Oct 9 2018, 1:14 PM
326–327 ↗(On Diff #168817)

How about DemandedMask.countTrailingZeros() >= C->getActiveBits()

dmgreen updated this revision to Diff 168971.Oct 10 2018, 3:46 AM
dmgreen edited the summary of this revision. (Show Details)

Updated to use activeBits. Thanks for the suggestions.

lebedev.ri accepted this revision.Oct 10 2018, 3:51 AM

Looks good, but maybe wait a bit for someone else to confirm.

This revision is now accepted and ready to land.Oct 10 2018, 3:51 AM
spatel accepted this revision.Oct 10 2018, 2:23 PM


spatel added inline comments.Oct 10 2018, 2:25 PM
323 ↗(On Diff #168971)

Add period at end of sentence.

This revision was automatically updated to reflect the committed changes.