This is an archive of the discontinued LLVM Phabricator instance.

[SDAG] Do not convert undef to 0 when folding CONCAT/BUILD_VECTOR
ClosedPublic

Authored by kparzysz on Sep 24 2020, 6:23 PM.

Details

Reviewers
craig.topper
Summary

When calling DAG.getNode(ISD::CONCAT_VECTOR, ...) with arguments that are BUILD_VECTOR and/or undef, the DAG will try to fold it into one large BUILD_VECTOR. In the process of preparing the operands, it may perform sign- or zero-extension of all values having width less than the required one. This includes undefs, which causes them to become zeros. This conversion from undef to "def" is not necessary and may inhibit further optimizations.

Concrete example: the original code had this operation in it:

v8i8 = BUILD_VECTOR t109, t109, t109, t109, t109, t109, t109, undef:i32

The operands were all of a legal type i32, i8 as a scalar is not legal on this target. The vector was then widened to v128i8 by concatenating it with a number of undef vectors. The folding described above broke up all these undef vectors into individual elements, and extended them to i32, which resulted in (unnecessarily) appending a number of 0s instead.

Diff Detail

Event Timeline

kparzysz created this revision.Sep 24 2020, 6:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 24 2020, 6:23 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
kparzysz requested review of this revision.Sep 24 2020, 6:23 PM
This revision is now accepted and ready to land.Sep 28 2020, 9:36 PM
kparzysz closed this revision.Sep 30 2020, 6:46 AM

Committed in db04bec5f1eeb581ee1470e5f444cc7b918c6d93. Somehow phabricator missed it and didn't close automatically.