This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyCFG] teach simplifycfg not to introduce ptrtoint for NI pointers
ClosedPublic

Authored by vtjnash on Jun 27 2022, 10:39 AM.

Details

Summary

SimplifyCFG expects to be able to cast both sides to an int, if either side can be case to an int, but this is not desirable or legal, in general, per D104547.

Spotted in https://github.com/JuliaLang/julia/issues/45702

Diff Detail

Event Timeline

vtjnash created this revision.Jun 27 2022, 10:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 27 2022, 10:39 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
vtjnash requested review of this revision.Jun 27 2022, 10:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 27 2022, 10:39 AM
vtjnash edited the summary of this revision. (Show Details)Jun 27 2022, 10:42 AM
vtjnash added reviewers: loladiro, mkazantsev.
vtjnash added a subscriber: Restricted Project.
nikic added a subscriber: nikic.Jun 28 2022, 1:38 AM
nikic added inline comments.
llvm/test/Transforms/SimplifyCFG/nonintegral.ll
3

Explicit verify is unnecessary. First RUN line can be dropped, they do the same thing. Please use update_test_checks.py.

vtjnash updated this revision to Diff 441761.Jul 1 2022, 11:54 AM

run tests once

llvm/test/Transforms/SimplifyCFG/nonintegral.ll
3

I used update_test_checks.py to generate these tests, but disliked the results, and edited them to the form here. Has policy changed such that it is now required to be used verbatim?

nikic accepted this revision.Jul 1 2022, 1:58 PM

LG

llvm/lib/Transforms/Utils/SimplifyCFG.cpp
478

I realize that this is pre-existing, but I found the code structure here somewhat confusing. I think it would be more obvious to write this as two separate checks:

// Normal constant int.
if (auto *CI = dyn_cast<ConstantInt>(V))
  return CI;

// Only handle constant integral pointers in the following.
if (!isa<Constant>(V) || !V->getType()->isPointerTy() ||
    DL.isNonIntegralPointerType(V->getType()))
  return nullptr;
llvm/test/Transforms/SimplifyCFG/nonintegral.ll
3

Yes, auto-generated check lines are preferred. If you want to make it more explicit what this test is about, maybe add a comment?

; Check that ptrtoint is not produced for non-integral address spaces.
6

The local_unnamed_addr #0 bit can be dropped.

This revision is now accepted and ready to land.Jul 1 2022, 1:58 PM
vtjnash added inline comments.Jul 6 2022, 12:02 PM
llvm/test/Transforms/SimplifyCFG/nonintegral.ll
3

That seems to be at odds with both the testing guide (which implies it is optional) https://llvm.org/docs/TestingGuide.html#generating-assertions-in-regression-tests
and the tool itself (which states the results should be edited to remove extra lines, and the output is not designed to be representative of a good test):
https://github.com/llvm-mirror/llvm/blob/2c4ca6832fa6b306ee6a7010bfb80a3f2596f824/utils/update_test_checks.py#L27-L29

vtjnash added inline comments.Jul 6 2022, 12:04 PM
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
478

I agree, if it was newly written, but also wasn't sure it warranted rearrangement, which would complicate the PR diff