This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] transform bitcasted bitwise logic ops with constants (PR26702)
ClosedPublic

Authored by spatel on Feb 24 2016, 3:17 PM.

Details

Summary

Given that we're not actually deleting any instructions in the included regression tests, I think we would call this a canonicalization step.

The motivation comes from the example in PR26702:
https://llvm.org/bugs/show_bug.cgi?id=26702

If we hoist the bitwise logic ahead of the bitcast, the previously unoptimizable example of:

define <4 x i32> @is_negative(<4 x i32> %x) {
  %lobit = ashr <4 x i32> %x, <i32 31, i32 31, i32 31, i32 31>
  %not = xor <4 x i32> %lobit, <i32 -1, i32 -1, i32 -1, i32 -1>
  %bc = bitcast <4 x i32> %not to <2 x i64>
  %notnot = xor <2 x i64> %bc, <i64 -1, i64 -1>
  %bc2 = bitcast <2 x i64> %notnot to <4 x i32>
  ret <4 x i32> %bc2
}

Simplifies to the expected:

define <4 x i32> @is_negative(<4 x i32> %x) {
  %lobit = ashr <4 x i32> %x, <i32 31, i32 31, i32 31, i32 31>
  ret <4 x i32> %lobit
}

Diff Detail

Repository
rL LLVM

Event Timeline

spatel updated this revision to Diff 48985.Feb 24 2016, 3:17 PM
spatel retitled this revision from to [InstCombine] transform bitcasted bitwise logic ops with constants (PR26702).
spatel updated this object.
spatel added reviewers: majnemer, hfinkel, mehdi_amini.
spatel added a subscriber: llvm-commits.
mehdi_amini accepted this revision.Mar 3 2016, 10:50 AM
mehdi_amini edited edge metadata.

LGTM.

This revision is now accepted and ready to land.Mar 3 2016, 10:50 AM
This revision was automatically updated to reflect the committed changes.

Thanks, Mehdi!