Page MenuHomePhabricator

[ConstantFold] Fold extractelement of getelementptr
ClosedPublic

Authored by foad on Oct 24 2019, 5:40 AM.

Details

Summary

Getelementptr has vector type if any of its operands are vectors
(the scalar operands being implicitly broadcast to all vector elements).
Extractelement applied to a vector getelementptr can be folded by
applying the extractelement in turn to all of the vector operands.

Diff Detail

Event Timeline

foad created this revision.Oct 24 2019, 5:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 24 2019, 5:40 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
reames accepted this revision.Oct 28 2019, 10:39 AM

LGTM

This revision is now accepted and ready to land.Oct 28 2019, 10:39 AM
This revision was automatically updated to reflect the committed changes.
efriedma added inline comments.Oct 28 2019, 5:16 PM
llvm/lib/IR/ConstantFold.cpp
811

This should probably be ConstantExpr::getExtractElement(), not ConstantFoldExtractElementInstruction. Pushing the extractelement into the operands should always be canonical. Granted, it's hard to come up with an example where that should make a difference.

foad marked an inline comment as done.Oct 29 2019, 3:36 AM
foad added inline comments.
llvm/lib/IR/ConstantFold.cpp
811

Agreed and fixed in dc63d6175aa.