This is an archive of the discontinued LLVM Phabricator instance.

DAG: ComputeNumSignBits from load range metadata
ClosedPublic

Authored by arsenm on Jun 4 2018, 3:35 AM.

Details

Summary

The cases where the result type doesn't match the range type
are inadequately tested, but I'm not sure how to write such a
test. During the pre-legalize combine, any obviously optimizable
code gets handled so it's harder to test legalized extloads.

Diff Detail

Event Timeline

arsenm created this revision.Jun 4 2018, 3:35 AM
nhaehnle added inline comments.Jun 25 2018, 12:48 AM
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
3536–3537 ↗(On Diff #149700)

First, this should probably use getSignedMin() and getSignedMax() instead of getLower() and getUpper(). An interesting test for this would be a range {i32 -1, i32 1}, which to my understanding only allows the values -1 and 0, so should have 32 sign bits, while the code as-is would say that it has 31 sign bits.

The other thing that worries me is what happens when there is a mismatch between the type used in the definition of the range metadata and the type returned by the SDNode. At the very least, there needs to be an assert to check against that case if we think it can't happen. If it can happen, it needs to be handled by taking the bit widths of the type of LD and of the APInts in the constant range into account.

test/CodeGen/AMDGPU/load-range-metadata-sign-bits.ll
6 ↗(On Diff #149700)

Spelling: *metadata

Also, why can't we always use v_bfe_i32 for (ashr (shl X, Y), Y) (and v_bfe_u32 for (lshr (shl X, Y), Y)), independent of any metadata?

nhaehnle added inline comments.Jun 25 2018, 12:50 AM
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
3536–3537 ↗(On Diff #149700)

I just double-checked, and at least the ConstantRange always has the same bit width for lower and upper bounds. But we still need to guard against that bit width being different from the bit width of the SDNode.

sanjoy resigned from this revision.Jan 29 2022, 5:30 PM
arsenm updated this revision to Diff 475637.Nov 15 2022, 5:07 PM
arsenm edited the summary of this revision. (Show Details)

Rebase, on top of baseline test commit. Also try to handle the unequal result size case, though poorly tested

Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 15 2022, 5:07 PM
RKSimon accepted this revision.Dec 5 2022, 4:50 AM

LGTM - cheers

This revision is now accepted and ready to land.Dec 5 2022, 4:50 AM