OSDN Git Service

[InstCombine] match De Morgan's Law hidden by zext ops (PR22723)
authorSanjay Patel <spatel@rotateright.com>
Fri, 25 Sep 2015 23:21:38 +0000 (23:21 +0000)
committerSanjay Patel <spatel@rotateright.com>
Fri, 25 Sep 2015 23:21:38 +0000 (23:21 +0000)
commit358e4088417ffbb59a269825daf6543742fa8eef
tree7d0348aca5751ee34571452631b9ecb97239605c
parentfed6bd86172fe5286db1aba61998f42ebaefd9f3
[InstCombine] match De Morgan's Law hidden by zext ops (PR22723)

This is a fix for PR22723:
https://llvm.org/bugs/show_bug.cgi?id=22723

My first attempt at this was to change what I thought was the root problem:

xor (zext i1 X to i32), 1 --> zext (xor i1 X, true) to i32

...but we create the opposite pattern in InstCombiner::visitZExt(), so infinite loop!

My next idea was to fix the matchIfNot() implementation in PatternMatch, but that would
mean potentially returning a different size for the match than what was input. I think
this would require all users of m_Not to check the size of the returned match, so I
abandoned that idea.

I settled on just fixing the exact case presented in the PR. This patch does allow the
2 functions in PR22723 to compile identically (x86):

bool test(bool x, bool y) { return !x | !y; }
bool test(bool x, bool y) { return !x || !y; }
...
andb %sil, %dil
xorb $1, %dil
movb %dil, %al
retq

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

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