OSDN Git Service

[InstCombine] don't use DeMorgan's Law on integer constants (2nd try)
authorSanjay Patel <spatel@rotateright.com>
Tue, 2 May 2017 15:31:40 +0000 (15:31 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 2 May 2017 15:31:40 +0000 (15:31 +0000)
commitdc1b8f42713b3ec1a8ecbdedb61ae9a63393db20
treeed2deb371cd9b8a5a17e5654446f5cda1fdcb649
parenta30d9c6883dd2b853358e8e26627d22f9ccaba9e
[InstCombine] don't use DeMorgan's Law on integer constants (2nd try)

This was originally checked in here:
https://reviews.llvm.org/rL301923

And reverted here:
https://reviews.llvm.org/rL301924

Because there's a clang test that would fail after this. I fixed/removed the
offending CHECK lines in:
https://reviews.llvm.org/rL301928

So let's try this again. Original commit message:

This is the fold that causes the infinite loop in BoringSSL
(https://github.com/google/boringssl/blob/master/crypto/cipher/e_rc2.c)
when we fix instcombine demanded bits to prefer 'not' ops as in https://reviews.llvm.org/D32255.

There are 2 or 3 problems with dyn_castNotVal, and I don't think we can
reinstate https://reviews.llvm.org/D32255 until dyn_castNotVal is completely eliminated.

1. As shown here, it transforms 'not' into random xor. This transform is harmful to SCEV and codegen because 'not' can often be folded while random xor cannot.
2. It does not transform vector constants. This is actually a good thing, but if you don't believe the above argument, then we shouldn't have excluded vectors.
3. It tries to avoid transforming not(not(X)). That's nice, but it doesn't match the greedy nature of instcombine. If we DeMorganize a pattern that has an extra 'not' in it: ~(~(~X) & Y) --> (~X | ~Y)

  That's just another case of DeMorgan, so we should trust that we'll fold that pattern too: (~X | ~ Y) --> ~(X & Y)

Differential Revision: https://reviews.llvm.org/D32665

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301929 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
test/Transforms/InstCombine/assume2.ll
test/Transforms/InstCombine/demorgan.ll