verification : https://alive2.llvm.org/ce/z/dgyUp7
Diff Detail
Unit Tests
Event Timeline
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.
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).