This is an archive of the discontinued LLVM Phabricator instance.

SeparateConstOffsetFromGEP: Don't use SCEV
ClosedPublic

Authored by arsenm on Jun 8 2023, 9:19 AM.

Details

Summary

This was only using the SCEV expressions as a map key, which we can
do just as well with the value pointers.

Diff Detail

Event Timeline

arsenm created this revision.Jun 8 2023, 9:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2023, 9:19 AM
arsenm requested review of this revision.Jun 8 2023, 9:19 AM
aeubanks added inline comments.Jun 8 2023, 9:23 AM
llvm/test/Transforms/SeparateConstOffsetFromGEP/AArch64/split-gep.ll
1 ↗(On Diff #529629)

-verify-scev is on in expensive builds so I don't think it's necessary to add it to many tests. maybe we should turn on the other two as well in expensive builds?

arsenm added inline comments.Jun 8 2023, 9:27 AM
llvm/test/Transforms/SeparateConstOffsetFromGEP/AArch64/split-gep.ll
1 ↗(On Diff #529629)

Currently can't turn them on because there are a lot of failures: https://github.com/llvm/llvm-project/issues/63195

nikic added inline comments.Jun 8 2023, 12:16 PM
llvm/test/Transforms/SeparateConstOffsetFromGEP/AArch64/split-gep.ll
1 ↗(On Diff #529629)

Please do not use any SCEV verification flags other than -verify-scev.

arsenm updated this revision to Diff 530088.Jun 9 2023, 2:44 PM

Drop test changes and rely on -verify-scev in EXPENSIVE_CHECKS

nikic added a comment.Jun 9 2023, 3:19 PM

I think this is okay, but I just took a look at what this pass actually does with SCEV and ... wat.

As far as I can tell, SCEV here can be replaced by using a std::pair<Value *, Value *> instead of a SCEV expressions in the DominatingAdd/DominatingSub maps. Might be better to do that and not request SCEV at all?

Might be better to do that and not request SCEV at all?

Possibly, but should be a separate patch. I'll file an issue to stop using SCEV here

Might be better to do that and not request SCEV at all?

Possibly, but should be a separate patch. I'll file an issue to stop using SCEV here

Went to describe the issue in the ticket and ended up with the patch which seems to work

arsenm updated this revision to Diff 533555.Jun 22 2023, 4:21 AM
arsenm retitled this revision from SeparateConstOffsetFromGEP: Preserve SCEV to SeparateConstOffsetFromGEP: Don't use SCEV.
arsenm edited the summary of this revision. (Show Details)

Don't use SCEV at all

nikic added inline comments.Jun 22 2023, 5:26 AM
llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
1235

I believe the previous code would also detect cases where the add operands are swapped as the same. Could add something like

static std::pair<Value *, Value *> createNormalizedPair(Value *A, Value *B) {
  if (A < B)
    return {A, B};
  return {B, A};
}

and use it for the add case to preserve that behavior. Though the fact that it's apparently untested is not reassuring...

arsenm updated this revision to Diff 534493.Jun 26 2023, 4:05 AM

Commute add keys and rebase on new tests for reuniteExts

arsenm added inline comments.Jun 26 2023, 4:41 AM
llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
1235

Most the code in the pass has sparse testing. I've rebased on a new test which showed this broke

1262

Wasn't sure about trying to preserve this behavior. Seems like it would only fire for constant cases, where you would expect the extension of constant to fold to a larger constant which wasn't pattern matched before

nikic accepted this revision.Jun 26 2023, 5:17 AM

LGTM

Nice to see that this also adds vector support as a side effect.

llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
1262

This doesn't constant fold either due to use of SCEVUnknown. The reason for the getNegativeSCEV call here is to prevent the commutation behavior for subs. In your new implementation it's no longer needed.

This revision is now accepted and ready to land.Jun 26 2023, 5:17 AM