This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Combine zext(trunc x) to x
ClosedPublic

Authored by Petar.Avramovic on Feb 4 2021, 6:17 AM.

Details

Summary

Combine zext(trunc x) to x when truncated bits are known to be zero.

Diff Detail

Event Timeline

Petar.Avramovic created this revision.Feb 4 2021, 6:17 AM
Petar.Avramovic requested review of this revision.Feb 4 2021, 6:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 4 2021, 6:17 AM
arsenm added a subscriber: arsenm.Feb 4 2021, 6:21 AM

Maybe should add a vector test, although known bits vector support may be too weak to test it

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
2312

getScalarSizeInBits

foad added a comment.Feb 4 2021, 6:27 AM

Looks good but I think it needs more test coverage. Does it work on vector types? (You might need to use getScalarSizeInBits instead of getSizeInBits?) If it does work on vectors then that needs tests.

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
2310

Maybe add a test case to check that this combine does nothing if the inner and outer types don't match?

Adding vectors.

foad accepted this revision.Feb 5 2021, 8:05 AM

LGTM.

llvm/test/CodeGen/AMDGPU/GlobalISel/combine-zext-trunc.mir
60–61 ↗(On Diff #321761)

In this case you could just use a trunc from s64 to s32. No need for the zext. That could be a follow-up though.

This revision is now accepted and ready to land.Feb 5 2021, 8:05 AM
foad added a comment.Feb 23 2021, 5:52 AM

Reverse ping.

This revision was automatically updated to reflect the committed changes.