[InstCombine] transform bitcasted bitwise logic ops with constants (PR26702)
authorSanjay Patel <spatel@rotateright.com>
Thu, 3 Mar 2016 19:19:04 +0000 (19:19 +0000)
committerSanjay Patel <spatel@rotateright.com>
Thu, 3 Mar 2016 19:19:04 +0000 (19:19 +0000)
commit9bba75084b7bde6a6215d616f664d3d2486f4871
tree8be3639147b06fb4a8e05435d20886eb75516436
parentdd12e9a8c04eb1cc5b43df4d249273678c5fec6b
[InstCombine] transform bitcasted bitwise logic ops with constants (PR26702)

Given that we're not actually reducing the instruction count 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
}

Differential Revision: http://reviews.llvm.org/D17583

llvm-svn: 262645
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/bitcast-bigendian.ll
llvm/test/Transforms/InstCombine/bitcast.ll