This is an archive of the discontinued LLVM Phabricator instance.

InstCombine: Fold some identities for canonicalize
ClosedPublic

Authored by arsenm on Nov 11 2022, 12:48 PM.

Details

Summary

Equality is directly stated as true in the LangRef,
and I believe this works for every compare type.

Diff Detail

Event Timeline

arsenm created this revision.Nov 11 2022, 12:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 11 2022, 12:48 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
arsenm requested review of this revision.Nov 11 2022, 12:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 11 2022, 12:48 PM
Herald added a subscriber: wdng. · View Herald Transcript
spatel added inline comments.Nov 18 2022, 11:00 AM
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
7109

Need to handle/test the commuted pattern too?

fcmp Pred x, canonical(x)
arsenm added inline comments.Nov 18 2022, 11:06 AM
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
7109

Have that, canonicalize_oeq_arg_f32 and canonicalize_oeq_arg_f32_commute

spatel added inline comments.Nov 18 2022, 11:31 AM
llvm/test/Transforms/InstCombine/canonicalize.ll
316–318

This isn't testing what was intended. The operands are canonicalized by complexity before we reach the transform in this patch.

It needs an extra instruction to create the expected pattern:

declare float @gen_f32()

define i1 @canonicalize_oeq_arg_f32_commute() {
  %x = call float @gen_f32() ; thwart complexity-based canonicalization
  %canon.x = call float @llvm.canonicalize.f32(float %x)
  %cmp = fcmp oeq float %x, %canon.x
  ret i1 %cmp
}
340–342

Similar to above - the operands got commuted.

arsenm added inline comments.Nov 18 2022, 11:43 AM
llvm/test/Transforms/InstCombine/canonicalize.ll
316–318

I thought the idea was to rely on the complexity based canonicalization, but I guess that's not good enough

arsenm updated this revision to Diff 476595.Nov 18 2022, 1:51 PM

Don't rely on commute canonicalization

spatel accepted this revision.Nov 21 2022, 7:24 AM

LGTM

This revision is now accepted and ready to land.Nov 21 2022, 7:24 AM