This is an archive of the discontinued LLVM Phabricator instance.

[instcombine] (extelt (inselt Vec, Value, Index), Index) -> Value
ClosedPublic

Authored by dsanders on Oct 10 2022, 3:30 PM.

Details

Summary

When Index is variable but still trivially known to be equal we can use Value
from before the insertion, possibly eliminating the vector.

Reverts a functional change from:
Author: Philip Reames <listmail@philipreames.com>
Date: Wed Dec 8 12:21:10 2021 -0800

[instcombine] A couple style tweaks to visitExtractElementInst [nfc]

Thanks to Michele Scandale for identifying the bug

Diff Detail

Event Timeline

dsanders created this revision.Oct 10 2022, 3:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 10 2022, 3:30 PM
dsanders requested review of this revision.Oct 10 2022, 3:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 10 2022, 3:30 PM
reames accepted this revision.Oct 10 2022, 3:39 PM

LGTM

And thank you for adding test coverage.

This revision is now accepted and ready to land.Oct 10 2022, 3:39 PM
This revision was landed with ongoing or failed builds.Oct 10 2022, 3:42 PM
This revision was automatically updated to reflect the committed changes.
paulwalker-arm added a subscriber: paulwalker-arm.EditedOct 14 2022, 3:17 AM

Sorry for the post commit question but I recall similar work being blocked when we wanted to say extractelt(splat(x), idx) -> x but the consensus was it could be an invalid transformation because if idx is out of range then the result is poison. Does this transformation fall into the same trap whereby we're incorrectly removing a source of poison? I'm not specifically seeking a revert I just want to understand the rules because for scalable vectors there are several instances where we are being hampered by such poison preservation.

nikic added a subscriber: nikic.Oct 14 2022, 3:32 AM

Sorry for the post commit question but I recall similar work being blocked when we wanted to say extractelt(splat(x), idx) -> x but the consensus was it could be an invalid transformation because if idx is out of range then the result is poison. Does this transformation fall into the same trap whereby we're incorrectly removing a source of poison? I'm not specifically seeking a revert I just want to understand the rules because for scalable vectors there are several instances where we are being hampered by such poison preservation.

It's fine to remove a source of poison, you just can't add one.

While the transform implemented here is correct, it is part of the wrong pass. This should be part of InstSimplify in simplifyExtractElementInst(). Can you please move it there?

It's fine to remove a source of poison, you just can't add one.

Thanks for the clarification @nikic.

While the transform implemented here is correct, it is part of the wrong pass. This should be part of InstSimplify in simplifyExtractElementInst(). Can you please move it there?

Sure, I've done that in https://reviews.llvm.org/D136099