This is an archive of the discontinued LLVM Phabricator instance.

Fix for PR23103. Correctly propagate the 'IsUndef' flag to the register operands of a commuted instruction.
ClosedPublic

Authored by andreadb on Apr 30 2015, 11:23 AM.

Details

Summary

Revision 220239 exposed a latent bug in method 'TargetInstrInfo::commuteInstruction'.

When commuting the operands of a machine instruction, method 'commuteInstruction' doesn't correctly propagate the 'IsUndef' flag to the register operands of the new (commuted) instruction.

Before this patch, the following instruction:

%vreg4<def> = VADDSDrr  %vreg14, %vreg5<undef>; FR64:%vreg4,%vreg14,%vreg5

was wrongly converted by method 'commuteInstruction' into:

%vreg4<def> = VADDSDrr  %vreg5, %vreg14<undef>; FR64:%vreg4,%vreg5,%vreg14

The correct instruction should have been:

%vreg4<def> = VADDSDrr  %vreg5<undef>, %vreg14; FR64:%vreg4,%vreg5,%vreg14

This patch fixes the problem in method 'TargetInstrInfo::commuteInstruction'. When swapping the operands of a machine instruction, we now make sure that 'IsUndef' flags are correctly set.
This fixes PR23103.

Added test case 'pr23103.ll' (obtained from the reproducible posted in PR23103).

Please let me know if ok to submit.

Thanks,
Andrea

Diff Detail

Repository
rL LLVM

Event Timeline

andreadb updated this revision to Diff 24750.Apr 30 2015, 11:23 AM
andreadb retitled this revision from to Fix for PR23103. Correctly propagate the 'IsUndef' flag to the register operands of a commuted instruction..
andreadb updated this object.
andreadb edited the test plan for this revision. (Show Details)
andreadb added a reviewer: qcolombet.
andreadb added a subscriber: Unknown Object (MLST).
qcolombet accepted this revision.Apr 30 2015, 11:33 AM
qcolombet edited edge metadata.

Hi Andrea,

Looks good to me with a nit on the test case.

Thanks,
-Quentin

test/CodeGen/X86/pr23103.ll
1 ↗(On Diff #24750)

Please add a few check lines, so to be sure we generate something sensible.

This revision is now accepted and ready to land.Apr 30 2015, 11:33 AM
This revision was automatically updated to reflect the committed changes.

Thanks for the review Quentin!

I managed to further simplify the test case.
I also added check lines to verify the output assembly as you suggested.

Committed revision 236258.