This is an archive of the discontinued LLVM Phabricator instance.

[ConstantFold] Teach how to fold a bitcast of a constant vector with some undef elements.
ClosedPublic

Authored by andreadb on Sep 7 2016, 10:19 AM.

Details

Summary

The previous logic didn't always know how to handle bitcasts of integer vectors with some undef elements.

The problem only affected the case where the bitcast vector type had more packed elements than the input vector type.

Example:

%cast = bitcast <2 x i64> <i64 undef, i64 2> to <4 x i32>

On a little endian target, that bitcast could be folded into the following constant vector:
<4 x i32><i32 undef, i32 undef, i32 2, i32 0>

However, the input vector had some undef elements, and the constant folder didn't know how to handle them.
This patch improves the logic by teaching how to deal with undefs.

Please let me know if okay to commit.
Thanks,
Andrea

Diff Detail

Repository
rL LLVM

Event Timeline

andreadb updated this revision to Diff 70553.Sep 7 2016, 10:19 AM
andreadb retitled this revision from to [ConstantFold] Teach how to fold a bitcast of a constant vector with some undef elements..
andreadb updated this object.
andreadb added reviewers: RKSimon, spatel, majnemer.
andreadb updated this object.
andreadb added a subscriber: llvm-commits.
ABataev added inline comments.
lib/Analysis/ConstantFolding.cpp
234–235 ↗(On Diff #70553)
Result.append(Ratio, UndefValue::get(DstEltTy));

?

andreadb added inline comments.Sep 13 2016, 2:42 AM
lib/Analysis/ConstantFolding.cpp
234–235 ↗(On Diff #70553)

Thanks Alexey, I am going to change it.

andreadb updated this revision to Diff 71129.Sep 13 2016, 3:31 AM

Patch updated.
Addressed Alexey's code review comment.

RKSimon edited edge metadata.Sep 13 2016, 5:44 AM

Please can you submit the current bitcast-vector-fold.ll tests to show the changes?

Please can you submit the current bitcast-vector-fold.ll tests to show the changes?

Sure, I am going to commit those tests now.
Then I will update the patch.

andreadb updated this revision to Diff 71159.Sep 13 2016, 6:44 AM
andreadb edited edge metadata.

Address Simon's review comment.

Patch rebased after revision 281332.

RKSimon accepted this revision.Sep 13 2016, 7:40 AM
RKSimon edited edge metadata.

LGTM

This revision is now accepted and ready to land.Sep 13 2016, 7:40 AM
This revision was automatically updated to reflect the committed changes.