This is an archive of the discontinued LLVM Phabricator instance.

[IR] Allow constant folding (insertelement <vscale x 2 x i32> zeroinitializer, i32 0, i32 i32 0.
ClosedPublic

Authored by craig.topper on Apr 8 2022, 10:37 AM.

Details

Summary

Most of insertelement constant folding is blocked if the vector type
is scalable. I believe we can make an exception for inserting null
into an all zeros vector.

Diff Detail

Event Timeline

craig.topper created this revision.Apr 8 2022, 10:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 8 2022, 10:37 AM
craig.topper requested review of this revision.Apr 8 2022, 10:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 8 2022, 10:37 AM
nikic added a subscriber: nikic.Apr 8 2022, 12:17 PM
nikic added inline comments.
llvm/lib/IR/ConstantFold.cpp
696

This could go before the CIdx check. Also, this holds fold any splat Val (e.g. UndefValue or PoisonValue), not just zero.

Move earlier. Add a TODO for undef/poison.

nikic accepted this revision.Apr 14 2022, 8:57 AM

LG, but please add a dedicated test for this (in test/Transforms/InstSimplify/ConstantFold or something).

This revision is now accepted and ready to land.Apr 14 2022, 8:57 AM
This revision was landed with ongoing or failed builds.Apr 15 2022, 5:44 PM
This revision was automatically updated to reflect the committed changes.
reames added a subscriber: reames.Apr 16 2022, 7:39 AM
reames added inline comments.
llvm/lib/IR/ConstantFold.cpp
687

I believe this should hold for any insertion of a constant into a splat of the same value. Poison/Undef/Zero are all just special cases of that.