This is an archive of the discontinued LLVM Phabricator instance.

[MIPS GlobalISel] Select icmp
ClosedPublic

Authored by Petar.Avramovic on Aug 30 2018, 8:02 AM.
Tokens
"Like" token, awarded by xiangzhai.

Details

Diff Detail

Repository
rL LLVM

Event Timeline

On MIPS 32 integer compare instruction are implicitly zero extended, meaning bitwise instructions (generated by legalizer) are superfluous. Where would be the best place to eliminate superfluous extends, perhaps upcoming prelegalize combiner ?

On MIPS 32 integer compare instruction are implicitly zero extended, meaning bitwise instructions (generated by legalizer) are superfluous. Where would be the best place to eliminate superfluous extends, perhaps upcoming prelegalize combiner ?

We currently don't have a good place for them but a pre/post-legalize combiner is where we expect them to end up. In this case, a post-legalize combiner that can use known-bits would probably be easiest since you'll have:

%2:_(s32) = G_ICMP intpred(ne), %0(s32), %1
%3:_(s32) = G_AND %2(s32), i32 1
$v0 = COPY %3(s32)

and can use the known-bits of G_ICMP to fold away the G_AND

lib/Target/Mips/MipsInstructionSelector.cpp
276 ↗(On Diff #163334)

I have a minor comment - I personally like using the MachineIRBuilder here as it takes slightly less code to write the above. Something like the following is cleaner IMO

MachineIRBuilder B(I);
for (const struct Instr &Instruction : Instructions) {
  auto MIB = B.buildInstr(Instruction.Opcode, Instruction.Def, Instruction.LHS);
  if (...) {}
  if (!MIB.constrainAllUses(TII, TRI, RBI))
     return false;
}
...
This revision is now accepted and ready to land.Sep 8 2018, 10:31 PM

Addressed review comments.

This revision was automatically updated to reflect the committed changes.