This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Fix multiply with overflow intrinsics legalization generating invalid MIR.
ClosedPublic

Authored by aemerson on Sep 29 2020, 2:53 PM.

Details

Summary

During lowering of G_UMULO and friends, the previous code moved the builder's insertion point to be after the legalizing instruction. When that happened, if there happened to be a "G_CONSTANT i32 0" immediately after, the CSEMIRBuilder would try to find that constant during the buildConstant(zero) call, and since it dominates itself would return the iterator unchanged, even though the def of the constant was *after* the current insertion point. This resulted in the compare being generated *before* the constant which it was using.

There's no need to modify the insertion point before building the mul-hi or constant. Delaying moving the insert point ensures those are built/CSEd before the G_ICMP is built.

We might still have a general issue with CSEMIRBuilder though with this edge case.

Fixes PR47679

Diff Detail

Event Timeline

aemerson created this revision.Sep 29 2020, 2:53 PM
aemerson requested review of this revision.Sep 29 2020, 2:53 PM

This is still a general CSEMIRBuilder issue I've worked around before

arsenm accepted this revision.Sep 29 2020, 3:52 PM
This revision is now accepted and ready to land.Sep 29 2020, 3:52 PM