This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Add tests for transforming `(icmp (xor X, Y), X)`; NFC
ClosedPublic

Authored by goldstein.w.n on Feb 22 2023, 5:20 PM.

Diff Detail

Event Timeline

goldstein.w.n created this revision.Feb 22 2023, 5:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 22 2023, 5:20 PM
goldstein.w.n requested review of this revision.Feb 22 2023, 5:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 22 2023, 5:20 PM
spatel added inline comments.Mar 6 2023, 6:30 AM
llvm/test/Transforms/InstCombine/icmp-of-xor-x.ll
42

Commute x and y on this instruction, so the test is not relying on another transform to get to canonical form.

72

Commute x and y on this instruction, so the test is not relying on another transform to get to canonical form.

73

This test is covering the same pattern (although with different types and predicate) as "xor_ule_2".
We're missing a test to provide coverage for a pattern like this:
x <= (y ^ x)

We can add an instruction to make sure the operands don't get commuted, and the test provides the coverage we want:

define i1 @xor_sge(i8 %xx, i8 %yy) {
  %x = mul i8 %xx, %xx      ; thwart complexity-based canonicalization
  %y = or i8 %yy, 128
  %xor = xor i8 %y, %x      ; both ops are binops, so they won't commute
  %r = icmp sge i8 %x, %xor ; both ops are binops, so they won't commute
  ret i1 %r
}
goldstein.w.n marked 3 inline comments as done.Mar 6 2023, 10:53 AM

Fixup tests to canonical form

spatel accepted this revision.Mar 6 2023, 10:56 AM

LGTM

This revision is now accepted and ready to land.Mar 6 2023, 10:56 AM