[x86] Rewrite the byte shift detection to not use boolean variables to
authorChandler Carruth <chandlerc@gmail.com>
Wed, 18 Feb 2015 07:13:48 +0000 (07:13 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Wed, 18 Feb 2015 07:13:48 +0000 (07:13 +0000)
commitc9520b48ae8100ae5fac48d067c04c8e9a86ac99
tree383242dbf9606eb58457096bf3ea736d381086e4
parentf781855732eb30952ddf0c4d80a4e2b34ac1c0fa
[x86] Rewrite the byte shift detection to not use boolean variables to
track state.

I didn't like this in the code review because the pattern tends to be
error prone, but I didn't see a clear way to rewrite it. Turns out that
there were bugs here, I found them when fuzz testing our shuffle
lowering for correctness on x86.

The core of the problem is that we need to consistently test all our
preconditions for the same directionality of shift and the same input
vector. Instead, formulate this as two predicates (one doesn't depend on
the input in any way), pass things like the directionality and input
vector as inputs, and loop over the alternatives.

This fixes a pattern of very rare miscompiles coming out of this code.
Turned up roughly 4 out of every 1 million v8 shuffles in my fuzz
testing. The new code is over half a million test runs with no failures
yet. I've also fuzzed every other function in the lowering code with
over 3.5 million test cases and not discovered any other miscompiles.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229642 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/vector-shuffle-128-v8.ll