2015-09-09 02:13:03 +08:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
|
|
|
|
|
|
|
; PR22723: Recognize De Morgan's Laws when obfuscated by zexts.
|
|
|
|
|
|
|
|
define i32 @demorgan_or(i1 %X, i1 %Y) {
|
|
|
|
%zextX = zext i1 %X to i32
|
|
|
|
%zextY = zext i1 %Y to i32
|
|
|
|
%notX = xor i32 %zextX, 1
|
|
|
|
%notY = xor i32 %zextY, 1
|
|
|
|
%or = or i32 %notX, %notY
|
|
|
|
ret i32 %or
|
|
|
|
|
|
|
|
; CHECK-LABEL: demorgan_or(
|
[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
llvm-svn: 248634
2015-09-26 07:21:38 +08:00
|
|
|
; CHECK-NEXT: %[[AND:.*]] = and i1 %X, %Y
|
|
|
|
; CHECK-NEXT: %[[ZEXT:.*]] = zext i1 %[[AND]] to i32
|
|
|
|
; CHECK-NEXT: %[[XOR:.*]] = xor i32 %[[ZEXT]], 1
|
|
|
|
; CHECK-NEXT: ret i32 %[[XOR]]
|
2015-09-09 02:13:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @demorgan_and(i1 %X, i1 %Y) {
|
|
|
|
%zextX = zext i1 %X to i32
|
|
|
|
%zextY = zext i1 %Y to i32
|
|
|
|
%notX = xor i32 %zextX, 1
|
|
|
|
%notY = xor i32 %zextY, 1
|
|
|
|
%and = and i32 %notX, %notY
|
|
|
|
ret i32 %and
|
|
|
|
|
|
|
|
; CHECK-LABEL: demorgan_and(
|
[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
llvm-svn: 248634
2015-09-26 07:21:38 +08:00
|
|
|
; CHECK-NEXT: %[[OR:.*]] = or i1 %X, %Y
|
|
|
|
; CHECK-NEXT: %[[ZEXT:.*]] = zext i1 %[[OR]] to i32
|
|
|
|
; CHECK-NEXT: %[[XOR:.*]] = xor i32 %[[ZEXT]], 1
|
|
|
|
; CHECK-NEXT: ret i32 %[[XOR]]
|
2015-09-09 02:13:03 +08:00
|
|
|
}
|
|
|
|
|