This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] [NFC] Move transforms for truncated shifts into narrowBinOp
ClosedPublic

Authored by Chenbing.Zheng on May 20 2022, 2:35 AM.

Diff Detail

Event Timeline

Chenbing.Zheng created this revision.May 20 2022, 2:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 20 2022, 2:35 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
Chenbing.Zheng requested review of this revision.May 20 2022, 2:35 AM
spatel requested changes to this revision.May 20 2022, 10:49 AM

Please make sure there is good test coverage and no compile-time problems before posting a patch for review.

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
687–710

This can't be correct - we are replacing shl with lshr?

709

This case falls through and creates a compile-time warning (when compiled by clang).

This revision now requires changes to proceed.May 20 2022, 10:49 AM

address comments

spatel accepted this revision.May 24 2022, 5:34 AM

LGTM - but please add a test to verify that we do not create a bug with shl.

I think this would have miscompiled with the previous revision of the patch:

define <2 x i8> @trunc_lshr_trunc(<2 x i64> %a) {
  %b = trunc <2 x i64> %a to <2 x i32>
  %c = shl <2 x i32> %b, <i32 9, i32 7>
  %d = trunc <2 x i32> %c to <2 x i8>
  ret <2 x i8> %d
}
This revision is now accepted and ready to land.May 24 2022, 5:34 AM
This revision was landed with ongoing or failed builds.May 24 2022, 7:25 PM
This revision was automatically updated to reflect the committed changes.

LGTM - but please add a test to verify that we do not create a bug with shl.

I think this would have miscompiled with the previous revision of the patch:

define <2 x i8> @trunc_lshr_trunc(<2 x i64> %a) {
  %b = trunc <2 x i64> %a to <2 x i32>
  %c = shl <2 x i32> %b, <i32 9, i32 7>
  %d = trunc <2 x i32> %c to <2 x i8>
  ret <2 x i8> %d
}

I commit it in https://reviews.llvm.org/rG793bb7049db012df4fe3ff6e8abc320677845400,and it pass after this patch.