This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Do not modify predicate when optimizing G_ICMP
ClosedPublic

Authored by paquette on May 26 2020, 1:04 PM.

Details

Summary

This fixes a bug in tryOptArithImmedIntegerCompare.

It is unsafe to update the predicate on a MachineOperand when optimizing a G_ICMP, because it may be used in more than one place.

For example, when we are optimizing G_SELECT, we allow compares which are used in more than one G_SELECT. If we modify the G_ICMP, then we'll break one of the G_SELECTs.

Since the compare is being produced to either

  1. Select a G_ICMP
  2. Fold a G_ICMP into an instruction when profitable

there's no reason to actually modify it. The change is local to the specific compare.

Instead, pass a CmpInst::Predicate to tryOptArithImmedIntegerCompare which can be modified by reference.

Diff Detail

Event Timeline

paquette created this revision.May 26 2020, 1:04 PM
paquette updated this revision to Diff 266334.May 26 2020, 2:35 PM

Fix bug with updating predicate early and add testcase

aemerson accepted this revision.May 26 2020, 5:15 PM

Ouch. Thanks for fixing this.

llvm/test/CodeGen/AArch64/GlobalISel/select-arith-immed-compare.mir
644

Please fix this comment as discussed.

This revision is now accepted and ready to land.May 26 2020, 5:15 PM
This revision was automatically updated to reflect the committed changes.