This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] Fold icmp comparing GEPs with global values
Needs ReviewPublic

Authored by ParkHanbum on Jun 24 2023, 6:08 AM.

Details

Diff Detail

Event Timeline

ParkHanbum created this revision.Jun 24 2023, 6:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2023, 6:08 AM
ParkHanbum requested review of this revision.Jun 24 2023, 6:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2023, 6:08 AM
nikic requested changes to this revision.Jun 24 2023, 6:24 AM

This needs to be split in two patches, one for the InstSimplify change and one for the ConstantFold change. In InstSimplify, you need to modify the code around the existing haveNonOverlappingStorage() call. What you need to do is subtract the offsets and reason about how the difference relates to the object size. It does not make sense to only handle the case where the offsets are the same.

This revision now requires changes to proceed.Jun 24 2023, 6:24 AM
ParkHanbum retitled this revision from [InstSimplify] Fold icmp between GEP to [InstSimplify] Fold icmp comparing GEPs with global values.

I modified it according to nikic's advice.

ParkHanbum edited the summary of this revision. (Show Details)Jun 26 2023, 3:51 AM

updated the code according to nikic's comment.

This condition isn't wrong, but it's also not as accurate as it could be.

Let's say LHSSize = 4, LHSOffset = 0, RHSSize = 2, RHSOffset = 2 with LHSOffset - RHSOffset = -2. These can be equal.

Then consider LHSSize = 4, LHSOffset = 2, RHSSize = 2, RHSOffset = 0 with LHSOffset - RHSOffset = 2. These cannot be equal.

As you can see, the sign of the result matters and we should not just take the absolute value.

I believe the condition should be Dist.isNonNegative() ? Dist.ult(LHSSize) : (-Dist).ult(RHSSize).

@nikic It looks neatly organized to me. how do you think?