This is an archive of the discontinued LLVM Phabricator instance.

[MIPS] BuildCondBr should preserve MO flags
ClosedPublic

Authored by npjdesres on Jun 8 2017, 9:55 AM.

Details

Summary

While simplifying branches in the MachineInstr representation, the
routine BuildCondBr must preserve flags on register MachineOperands. In
particular, it must preserve the <undef> flag.

This fixes a bug that is unlikely to occur in any real scenario, but
which bugpoint is likely to introduce.

Diff Detail

Repository
rL LLVM

Event Timeline

npjdesres created this revision.Jun 8 2017, 9:55 AM
npjdesres updated this revision to Diff 101940.Jun 8 2017, 10:21 AM

Updated patch to include greater context.

ahatanak edited edge metadata.

I haven't looked at this code recently, so someone currently working on mips should review the patch.

lib/Target/Mips/MipsInstrInfo.cpp
107 ↗(On Diff #101940)

I wonder why MachineInstrBuilder::add wasn't called to add regs and imms?

test/CodeGen/Mips/brundef.ll
123 ↗(On Diff #101940)

Test case can be simpler. You can probably remove some of the basic blocks and attributes and metadata that don't affect code-gen.

sdardis requested changes to this revision.Jun 9 2017, 7:21 AM

Some small changes requested, inlined. Can you also simplify the test case?

Thanks for doing this.
Simon

lib/Target/Mips/MipsInstrInfo.cpp
106–111 ↗(On Diff #101940)

As Akira notes, this can all be refactored to:

assert((Cond[i].isImm() || Cond[i].isReg()) && "Cannot copy operand for conditional branch!");
MIB.add(Cond[i]);
107 ↗(On Diff #101940)

It appears the code was simply extended to accept immediates for mips16, suggesting that at one point perhaps there was some pseudo branch instruction that took an immediate?

I quickly tested removing the immediate case and it passed the codegen section of test-suite, suggesting the immediate case is dead code (or that our test coverage doesn't cover that case).

test/CodeGen/Mips/brundef.ll
1 ↗(On Diff #101940)

This runline should be: llc -march=mips -mcpu=mips32 < %s -verify-machineinstrs -o /dev/null

The '> %t' is un-necessary if we're testing that the program can be compiled without a verifier error, so we don't need to preserve the output.

The -mcpu=mips32 silences a warning from llc about there being no 'generic' processor for mips.

Please also add a short comment describing what the purpose of this test.

2 ↗(On Diff #101940)

You can remove the 'local_unnamed_addr #0 align 2' here.

This revision now requires changes to proceed.Jun 9 2017, 7:21 AM
npjdesres updated this revision to Diff 102247.Jun 12 2017, 3:22 PM
npjdesres edited edge metadata.

Update to reflect reviews. Shorter testcase.

sdardis accepted this revision.Jun 13 2017, 3:08 AM

LGTM.

Do you need me to commit this for you?

Thanks for doing this.
Simon

This revision is now accepted and ready to land.Jun 13 2017, 3:08 AM

I do not have commit access, so if you could commit this I would appreciate it. Thank you.

This revision was automatically updated to reflect the committed changes.