This is an archive of the discontinued LLVM Phabricator instance.

[IR] In ConstantFoldShuffleVectorInstruction use zeroinitializer for splats of 0
ClosedPublic

Authored by david-arm on Nov 8 2021, 5:25 AM.

Details

Summary

When creating a splat of 0 for scalable vectors we tend to create them
with using a combination of shufflevector and insertelement, i.e.

shufflevector (<vscale x 4 x i32> insertelement (<vscale x 4 x i32> poison, i32 0, i32 0),

<vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer)

However, for the case of a zero splat we can actually just replace the
above with zeroinitializer instead. This makes the IR a lot simpler and
easier to read. I have changed ConstantFoldShuffleVectorInstruction to
use zeroinitializer when creating a splat of integer 0 or FP +0.0 values.

Diff Detail

Event Timeline

david-arm created this revision.Nov 8 2021, 5:25 AM
david-arm requested review of this revision.Nov 8 2021, 5:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 8 2021, 5:25 AM
sdesmalen accepted this revision.Nov 8 2021, 5:34 AM

That's a great change, which happens to make some of the tests a bit more readable. Thanks!

llvm/lib/IR/ConstantFold.cpp
739

nit: maybe add a comment to describe why it's testing specifically for +0.0? (I assume that is because zeroinitializer is positive)

This revision is now accepted and ready to land.Nov 8 2021, 5:34 AM
david-arm updated this revision to Diff 385756.Nov 9 2021, 3:25 AM
  • Fixed up some failing tests that I'd previously missed.
  • Added comment about +0.0 FP values.
david-arm marked an inline comment as done.Nov 9 2021, 3:25 AM
nikic added a subscriber: nikic.Nov 9 2021, 3:36 AM
nikic added inline comments.
llvm/lib/IR/ConstantFold.cpp
742

Shouldn't this just use Elt->isNullValue() instead of Elt->isZeroValue()?

david-arm updated this revision to Diff 385764.Nov 9 2021, 3:55 AM
  • Use isNullValue instead of isZeroValue
david-arm marked an inline comment as done.Nov 9 2021, 3:56 AM
david-arm added inline comments.
llvm/lib/IR/ConstantFold.cpp
742

That's a great suggestion @nikic, thanks!

ThomasRaoux accepted this revision.Nov 9 2021, 10:08 AM
ThomasRaoux removed a reviewer: ThomasRaoux.
Herald added a project: Restricted Project. · View Herald TranscriptNov 10 2021, 1:44 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript