This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] add fold (X > C - 1) ^ (X < C + 1) --> X != C
ClosedPublic

Authored by Chenbing.Zheng on Jul 13 2022, 12:50 AM.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2022, 12:50 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
Chenbing.Zheng requested review of this revision.Jul 13 2022, 12:50 AM
spatel added inline comments.Jul 14 2022, 10:49 AM
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
3216

Did you make a general proof for this on alive2? Please add a link to the patch summary. I don't think this will be correct if the "+2" overflows?

spatel added inline comments.Jul 18 2022, 11:58 AM
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
3226

There is no check that LHS0 is the same as RHS0. Please correct that and add a test similar to this:

define i1 @xor_of_icmps_to_ne_no_common_operand(i64 %a, i64 %z) {
  %b = icmp sgt i64 %z, 4
  %c = icmp slt i64 %a, 6
  %xor = xor i1 %b, %c
  ret i1 %xor
}
llvm/test/Transforms/InstCombine/set.ll
259

Similar to my comment from D129726:
You may pre-commit tests in "NFC" patches. You can push that kind of patch without pre-commit review on Phabricator. It would be good to test at least 2 more code patterns:

  1. Use a vector type with "splat" constants.
  2. Add extra uses of the icmps.

address comment

spatel edited the summary of this revision. (Show Details)Jul 20 2022, 7:18 AM
spatel accepted this revision.Jul 20 2022, 7:23 AM

LGTM - I think this could be implemented more generally using ConstantRange, but we already get the inverted pattern because the constants are equal in that case, so handling this specific pattern is ok.

This revision is now accepted and ready to land.Jul 20 2022, 7:23 AM