This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] bitcast(logic(bitcast(X), bitcast(Y))) --> bitcast'(logic(bitcast'(X), Y))
ClosedPublic

Authored by Chenbing.Zheng on May 22 2022, 11:51 PM.

Details

Summary

Before this patch foldBitCastBitwiseLogic limite the destination
must have an integer element type.

But we can still eliminate one bitcast by doing the logic op
in the type of the input that has an integer element type.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptMay 22 2022, 11:51 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
Chenbing.Zheng requested review of this revision.May 22 2022, 11:51 PM

This seems fine, but we should improve the tests.

llvm/test/Transforms/InstCombine/bitcast.ll
135

This is exactly the same test as the one in the earlier file? We should change it to provide more coverage. Vary the types, commute the operands, use xor, etc.

define <4 x float> @bitcasts_xor_bitcast_to_fp(<2 x double> %a, <8 x i16> %b) {
  %bc1 = bitcast <8 x i16> %b to <2 x i64>
  %bc2 = bitcast <2 x double> %a to <2 x i64>
  %xor = xor <2 x i64> %bc2, %bc1
  %bc3 = bitcast <2 x i64> %xor to <4 x float>
  ret <4 x float> %bc3
}

If we do not have (negative) tests with extra uses, please add those too.

spatel accepted this revision.May 25 2022, 4:53 AM

LGTM

llvm/test/Transforms/InstCombine/bitcast.ll
177

Spelling - "Negative"

This revision is now accepted and ready to land.May 25 2022, 4:53 AM
This revision was landed with ongoing or failed builds.May 25 2022, 8:04 PM
This revision was automatically updated to reflect the committed changes.