This is an archive of the discontinued LLVM Phabricator instance.

Delay slot filler: Replace the microMIPS BEQ/BNE with the BEQZC/BNEZC
ClosedPublic

Authored by jkolek on Apr 30 2014, 4:40 AM.

Details

Summary

This patch implements functionality in MIPS delay slot filler such as if delay slot filler have to put NOP instruction into the delay slot of microMIPS BEQ or BNE instruction which uses the register $0, then instead of emitting NOP this instruction is replaced by the corresponding microMIPS compact branch instruction, i.e. BEQZC or BNEZC.

Diff Detail

Repository
rL LLVM

Event Timeline

jkolek updated this revision to Diff 8966.Apr 30 2014, 4:40 AM
jkolek retitled this revision from to Delay slot filler: Replace the microMIPS BEQ/BNE with the BEQZC/BNEZC.
jkolek updated this object.
jkolek edited the test plan for this revision. (Show Details)
jkolek added reviewers: dsanders, matheusalmeida.
jkolek added subscribers: zoran.jovanovic, petarj.
dsanders accepted this revision.Jun 11 2014, 8:16 AM
dsanders edited edge metadata.

LGTM with micromips-long-branch.ll change explained, and with the Br->hasDelaySlot() change.

lib/Target/Mips/MipsDelaySlotFiller.cpp
535–546 ↗(On Diff #8966)

You don't have to do it in this patch, but the same trick will be useful for MIPS32r6/MIPS64r6. It would be good to use a try/fallback approach so we don't have to add several if-statements. E.g something like:

if (!replaceWithCompactBranch(...))
    bundle a NOP with the branch

where replaceWithCompactBranch() returns true if it sucessfully used a compact branch.

lib/Target/Mips/MipsLongBranch.cpp
240–241 ↗(On Diff #8966)

I believe this should be:

if (!Br->hasDelaySlot())
  ...
test/CodeGen/Mips/micromips-long-branch.ll
16423 ↗(On Diff #8966)

Why did this change when nothing else in the file did? I can't think of a reason the patch would change it.

This revision is now accepted and ready to land.Jun 11 2014, 8:16 AM
jkolek edited edge metadata.Nov 18 2014, 5:40 AM
jkolek added a subscriber: Unknown Object (MLST).
jkolek updated this revision to Diff 16505.Nov 21 2014, 12:28 PM
jkolek removed a reviewer: matheusalmeida.

Rebased patch:

In the function MipsLongBranch::replaceBranch() the condition:

((unsigned) Br->getOpcode()) != Mips::BEQZC_MM && ((unsigned) Br->getOpcode()) != Mips::BNEZC_MM

is replaced with:

Br->hasDelaySlot()

The file 'test/CodeGen/Mips/micromips-long-branch.ll' has been removed since by commit 207656. MicroMIPS long branch is now tested in the file 'test/CodeGen/Mips/longbranch.ll'. Back then the change of value of ADDIU instruction was due to its role in calculation of long branches. The immediate part of ADDIU was something like %lo(($lab1)-($lab2)), and because BEQZ was between $lab1 and $lab2 after it was replaced by BEQZC (no NOP anymore) the immediate value of ADDIU was changed.

jkolek closed this revision.Nov 21 2014, 2:04 PM
jkolek updated this revision to Diff 16510.

Closed by commit rL222580 (authored by @jkolek).