2017-06-22 13:20:39 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
2016-03-17 07:20:20 +08:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
2007-06-15 13:57:20 +08:00
|
|
|
|
|
|
|
; PR1510
|
|
|
|
|
2017-04-23 07:36:47 +08:00
|
|
|
; (a | b) & ~(a & b) --> a ^ b
|
|
|
|
|
2017-04-23 21:37:05 +08:00
|
|
|
define i32 @and_to_xor1(i32 %a, i32 %b) {
|
|
|
|
; CHECK-LABEL: @and_to_xor1(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[AND2:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
|
2017-04-23 21:37:05 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[AND2]]
|
|
|
|
;
|
|
|
|
%or = or i32 %a, %b
|
|
|
|
%and = and i32 %a, %b
|
|
|
|
%not = xor i32 %and, -1
|
|
|
|
%and2 = and i32 %or, %not
|
|
|
|
ret i32 %and2
|
|
|
|
}
|
|
|
|
|
|
|
|
; ~(a & b) & (a | b) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @and_to_xor2(i32 %a, i32 %b) {
|
|
|
|
; CHECK-LABEL: @and_to_xor2(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[AND2:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
|
2017-04-23 21:37:05 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[AND2]]
|
|
|
|
;
|
|
|
|
%or = or i32 %a, %b
|
|
|
|
%and = and i32 %a, %b
|
|
|
|
%not = xor i32 %and, -1
|
|
|
|
%and2 = and i32 %not, %or
|
|
|
|
ret i32 %and2
|
|
|
|
}
|
|
|
|
|
|
|
|
; (a | b) & ~(b & a) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @and_to_xor3(i32 %a, i32 %b) {
|
|
|
|
; CHECK-LABEL: @and_to_xor3(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[AND2:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
|
2017-04-23 07:36:47 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[AND2]]
|
|
|
|
;
|
2017-04-23 21:37:05 +08:00
|
|
|
%or = or i32 %a, %b
|
2017-04-23 07:36:47 +08:00
|
|
|
%and = and i32 %b, %a
|
|
|
|
%not = xor i32 %and, -1
|
|
|
|
%and2 = and i32 %or, %not
|
|
|
|
ret i32 %and2
|
2007-06-15 13:57:20 +08:00
|
|
|
}
|
|
|
|
|
2017-04-23 21:37:05 +08:00
|
|
|
; ~(a & b) & (b | a) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @and_to_xor4(i32 %a, i32 %b) {
|
|
|
|
; CHECK-LABEL: @and_to_xor4(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[AND2:%.*]] = xor i32 [[B:%.*]], [[A:%.*]]
|
2017-04-23 21:37:05 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[AND2]]
|
|
|
|
;
|
|
|
|
%or = or i32 %b, %a
|
|
|
|
%and = and i32 %a, %b
|
|
|
|
%not = xor i32 %and, -1
|
|
|
|
%and2 = and i32 %not, %or
|
|
|
|
ret i32 %and2
|
|
|
|
}
|
|
|
|
|
|
|
|
define <4 x i32> @and_to_xor1_vec(<4 x i32> %a, <4 x i32> %b) {
|
|
|
|
; CHECK-LABEL: @and_to_xor1_vec(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[AND2:%.*]] = xor <4 x i32> [[A:%.*]], [[B:%.*]]
|
2017-04-23 07:36:47 +08:00
|
|
|
; CHECK-NEXT: ret <4 x i32> [[AND2]]
|
|
|
|
;
|
|
|
|
%or = or <4 x i32> %a, %b
|
|
|
|
%and = and <4 x i32> %a, %b
|
|
|
|
%not = xor <4 x i32> %and, < i32 -1, i32 -1, i32 -1, i32 -1 >
|
|
|
|
%and2 = and <4 x i32> %or, %not
|
|
|
|
ret <4 x i32> %and2
|
2007-06-15 13:57:20 +08:00
|
|
|
}
|
|
|
|
|
2017-04-24 04:59:00 +08:00
|
|
|
; In the next 4 tests, cast instructions are used to thwart operand complexity
|
|
|
|
; canonicalizations, so we can test all of the commuted patterns.
|
|
|
|
|
2017-04-24 06:00:02 +08:00
|
|
|
; (a | ~b) & (~a | b) --> ~(a ^ b)
|
|
|
|
|
2017-04-24 04:59:00 +08:00
|
|
|
define i32 @and_to_nxor1(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @and_to_nxor1(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-04-24 06:00:02 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[A]], [[B]]
|
|
|
|
; CHECK-NEXT: [[AND:%.*]] = xor i32 [[TMP1]], -1
|
2017-04-24 04:59:00 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[AND]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%or1 = or i32 %a, %notb
|
|
|
|
%or2 = or i32 %nota, %b
|
|
|
|
%and = and i32 %or1, %or2
|
|
|
|
ret i32 %and
|
|
|
|
}
|
|
|
|
|
2017-04-24 06:00:02 +08:00
|
|
|
; (a | ~b) & (b | ~a) --> ~(a ^ b)
|
|
|
|
|
2017-04-24 04:59:00 +08:00
|
|
|
define i32 @and_to_nxor2(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @and_to_nxor2(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-04-24 06:00:02 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[A]], [[B]]
|
|
|
|
; CHECK-NEXT: [[AND:%.*]] = xor i32 [[TMP1]], -1
|
2017-04-24 04:59:00 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[AND]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%or1 = or i32 %a, %notb
|
|
|
|
%or2 = or i32 %b, %nota
|
|
|
|
%and = and i32 %or1, %or2
|
|
|
|
ret i32 %and
|
|
|
|
}
|
|
|
|
|
2017-04-24 06:00:02 +08:00
|
|
|
; (~a | b) & (a | ~b) --> ~(a ^ b)
|
|
|
|
|
2017-04-24 04:59:00 +08:00
|
|
|
define i32 @and_to_nxor3(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @and_to_nxor3(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-04-24 06:00:02 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[B]], [[A]]
|
|
|
|
; CHECK-NEXT: [[AND:%.*]] = xor i32 [[TMP1]], -1
|
2017-04-24 04:59:00 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[AND]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%or1 = or i32 %nota, %b
|
|
|
|
%or2 = or i32 %a, %notb
|
|
|
|
%and = and i32 %or1, %or2
|
|
|
|
ret i32 %and
|
|
|
|
}
|
|
|
|
|
2017-04-24 06:00:02 +08:00
|
|
|
; (~a | b) & (~b | a) --> ~(a ^ b)
|
|
|
|
|
2017-04-24 04:59:00 +08:00
|
|
|
define i32 @and_to_nxor4(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @and_to_nxor4(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-04-24 06:00:02 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[B]], [[A]]
|
|
|
|
; CHECK-NEXT: [[AND:%.*]] = xor i32 [[TMP1]], -1
|
2017-04-24 04:59:00 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[AND]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%or1 = or i32 %nota, %b
|
|
|
|
%or2 = or i32 %notb, %a
|
|
|
|
%and = and i32 %or1, %or2
|
|
|
|
ret i32 %and
|
|
|
|
}
|
|
|
|
|
2017-04-24 00:37:36 +08:00
|
|
|
; (a & ~b) | (~a & b) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @or_to_xor1(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @or_to_xor1(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-04-24 00:37:36 +08:00
|
|
|
; CHECK-NEXT: [[OR:%.*]] = xor i32 [[A]], [[B]]
|
|
|
|
; CHECK-NEXT: ret i32 [[OR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%and1 = and i32 %a, %notb
|
|
|
|
%and2 = and i32 %nota, %b
|
|
|
|
%or = or i32 %and1, %and2
|
|
|
|
ret i32 %or
|
|
|
|
}
|
|
|
|
|
|
|
|
; (a & ~b) | (b & ~a) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @or_to_xor2(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @or_to_xor2(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-04-24 00:37:36 +08:00
|
|
|
; CHECK-NEXT: [[OR:%.*]] = xor i32 [[A]], [[B]]
|
|
|
|
; CHECK-NEXT: ret i32 [[OR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%and1 = and i32 %a, %notb
|
|
|
|
%and2 = and i32 %b, %nota
|
|
|
|
%or = or i32 %and1, %and2
|
|
|
|
ret i32 %or
|
|
|
|
}
|
|
|
|
|
|
|
|
; (~a & b) | (~b & a) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @or_to_xor3(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @or_to_xor3(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-04-24 00:37:36 +08:00
|
|
|
; CHECK-NEXT: [[OR:%.*]] = xor i32 [[B]], [[A]]
|
|
|
|
; CHECK-NEXT: ret i32 [[OR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%and1 = and i32 %nota, %b
|
|
|
|
%and2 = and i32 %notb, %a
|
|
|
|
%or = or i32 %and1, %and2
|
|
|
|
ret i32 %or
|
|
|
|
}
|
|
|
|
|
|
|
|
; (~a & b) | (a & ~b) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @or_to_xor4(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @or_to_xor4(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-04-24 00:37:36 +08:00
|
|
|
; CHECK-NEXT: [[OR:%.*]] = xor i32 [[B]], [[A]]
|
|
|
|
; CHECK-NEXT: ret i32 [[OR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%and1 = and i32 %nota, %b
|
|
|
|
%and2 = and i32 %a, %notb
|
|
|
|
%or = or i32 %and1, %and2
|
|
|
|
ret i32 %or
|
|
|
|
}
|
|
|
|
|
2017-04-24 06:00:02 +08:00
|
|
|
; (a & b) | ~(a | b) --> ~(a ^ b)
|
|
|
|
|
2017-04-24 04:59:00 +08:00
|
|
|
define i32 @or_to_nxor1(i32 %a, i32 %b) {
|
|
|
|
; CHECK-LABEL: @or_to_nxor1(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
|
2017-04-24 06:00:02 +08:00
|
|
|
; CHECK-NEXT: [[OR2:%.*]] = xor i32 [[TMP1]], -1
|
2017-04-24 04:59:00 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[OR2]]
|
|
|
|
;
|
|
|
|
%and = and i32 %a, %b
|
|
|
|
%or = or i32 %a, %b
|
|
|
|
%notor = xor i32 %or, -1
|
|
|
|
%or2 = or i32 %and, %notor
|
|
|
|
ret i32 %or2
|
|
|
|
}
|
|
|
|
|
2017-04-24 06:00:02 +08:00
|
|
|
; (a & b) | ~(b | a) --> ~(a ^ b)
|
|
|
|
|
2017-04-24 04:59:00 +08:00
|
|
|
define i32 @or_to_nxor2(i32 %a, i32 %b) {
|
|
|
|
; CHECK-LABEL: @or_to_nxor2(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
|
2017-04-24 06:00:02 +08:00
|
|
|
; CHECK-NEXT: [[OR2:%.*]] = xor i32 [[TMP1]], -1
|
2017-04-24 04:59:00 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[OR2]]
|
|
|
|
;
|
|
|
|
%and = and i32 %a, %b
|
|
|
|
%or = or i32 %b, %a
|
|
|
|
%notor = xor i32 %or, -1
|
|
|
|
%or2 = or i32 %and, %notor
|
|
|
|
ret i32 %or2
|
|
|
|
}
|
|
|
|
|
2017-04-24 06:00:02 +08:00
|
|
|
; ~(a | b) | (a & b) --> ~(a ^ b)
|
|
|
|
|
2017-04-24 04:59:00 +08:00
|
|
|
define i32 @or_to_nxor3(i32 %a, i32 %b) {
|
|
|
|
; CHECK-LABEL: @or_to_nxor3(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
|
2017-04-24 06:00:02 +08:00
|
|
|
; CHECK-NEXT: [[OR2:%.*]] = xor i32 [[TMP1]], -1
|
2017-04-24 04:59:00 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[OR2]]
|
|
|
|
;
|
|
|
|
%and = and i32 %a, %b
|
|
|
|
%or = or i32 %a, %b
|
|
|
|
%notor = xor i32 %or, -1
|
|
|
|
%or2 = or i32 %notor, %and
|
|
|
|
ret i32 %or2
|
|
|
|
}
|
|
|
|
|
2017-04-24 06:00:02 +08:00
|
|
|
; ~(a | b) | (b & a) --> ~(a ^ b)
|
|
|
|
|
2017-04-24 04:59:00 +08:00
|
|
|
define i32 @or_to_nxor4(i32 %a, i32 %b) {
|
|
|
|
; CHECK-LABEL: @or_to_nxor4(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[B:%.*]], [[A:%.*]]
|
2017-04-24 06:00:02 +08:00
|
|
|
; CHECK-NEXT: [[OR2:%.*]] = xor i32 [[TMP1]], -1
|
2017-04-24 04:59:00 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[OR2]]
|
|
|
|
;
|
|
|
|
%and = and i32 %b, %a
|
|
|
|
%or = or i32 %a, %b
|
|
|
|
%notor = xor i32 %or, -1
|
|
|
|
%or2 = or i32 %notor, %and
|
|
|
|
ret i32 %or2
|
|
|
|
}
|
|
|
|
|
2017-04-23 22:51:03 +08:00
|
|
|
; (a & b) ^ (a | b) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @xor_to_xor1(i32 %a, i32 %b) {
|
|
|
|
; CHECK-LABEL: @xor_to_xor1(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
|
2017-04-23 22:51:03 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%and = and i32 %a, %b
|
|
|
|
%or = or i32 %a, %b
|
|
|
|
%xor = xor i32 %and, %or
|
|
|
|
ret i32 %xor
|
|
|
|
}
|
|
|
|
|
|
|
|
; (a & b) ^ (b | a) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @xor_to_xor2(i32 %a, i32 %b) {
|
|
|
|
; CHECK-LABEL: @xor_to_xor2(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
|
2017-04-23 22:51:03 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%and = and i32 %a, %b
|
|
|
|
%or = or i32 %b, %a
|
|
|
|
%xor = xor i32 %and, %or
|
|
|
|
ret i32 %xor
|
|
|
|
}
|
|
|
|
|
|
|
|
; (a | b) ^ (a & b) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @xor_to_xor3(i32 %a, i32 %b) {
|
|
|
|
; CHECK-LABEL: @xor_to_xor3(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
|
2017-04-23 22:51:03 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%or = or i32 %a, %b
|
|
|
|
%and = and i32 %a, %b
|
|
|
|
%xor = xor i32 %or, %and
|
|
|
|
ret i32 %xor
|
|
|
|
}
|
|
|
|
|
|
|
|
; (a | b) ^ (b & a) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @xor_to_xor4(i32 %a, i32 %b) {
|
|
|
|
; CHECK-LABEL: @xor_to_xor4(
|
[PatternMatch] Stabilize the matching order of commutative matchers
Summary:
Currently, we
1. match `LHS` matcher to the `first` operand of binary operator,
2. and then match `RHS` matcher to the `second` operand of binary operator.
If that does not match, we swap the `LHS` and `RHS` matchers:
1. match `RHS` matcher to the `first` operand of binary operator,
2. and then match `LHS` matcher to the `second` operand of binary operator.
This works ok.
But it complicates writing of commutative matchers, where one would like to match
(`m_Value()`) the value on one side, and use (`m_Specific()`) it on the other side.
This is additionally complicated by the fact that `m_Specific()` stores the `Value *`,
not `Value **`, so it won't work at all out of the box.
The last problem is trivially solved by adding a new `m_c_Specific()` that stores the
`Value **`, not `Value *`. I'm choosing to add a new matcher, not change the existing
one because i guess all the current users are ok with existing behavior,
and this additional pointer indirection may have performance drawbacks.
Also, i'm storing pointer, not reference, because for some mysterious-to-me reason
it did not work with the reference.
The first one appears trivial, too.
Currently, we
1. match `LHS` matcher to the `first` operand of binary operator,
2. and then match `RHS` matcher to the `second` operand of binary operator.
If that does not match, we swap the ~~`LHS` and `RHS` matchers~~ **operands**:
1. match ~~`RHS`~~ **`LHS`** matcher to the ~~`first`~~ **`second`** operand of binary operator,
2. and then match ~~`LHS`~~ **`RHS`** matcher to the ~~`second`~ **`first`** operand of binary operator.
Surprisingly, `$ ninja check-llvm` still passes with this.
But i expect the bots will disagree..
The motivational unittest is included.
I'd like to use this in D45664.
Reviewers: spatel, craig.topper, arsenm, RKSimon
Reviewed By: craig.topper
Subscribers: xbolva00, wdng, llvm-commits
Differential Revision: https://reviews.llvm.org/D45828
llvm-svn: 331085
2018-04-28 05:23:20 +08:00
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[B:%.*]], [[A:%.*]]
|
2017-04-23 22:51:03 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%or = or i32 %a, %b
|
|
|
|
%and = and i32 %b, %a
|
|
|
|
%xor = xor i32 %or, %and
|
|
|
|
ret i32 %xor
|
|
|
|
}
|
|
|
|
|
|
|
|
; (a | ~b) ^ (~a | b) --> a ^ b
|
|
|
|
|
2017-04-24 00:03:00 +08:00
|
|
|
; In the next 8 tests, cast instructions are used to thwart operand complexity
|
2017-04-23 22:51:03 +08:00
|
|
|
; canonicalizations, so we can test all of the commuted patterns.
|
|
|
|
|
|
|
|
define i32 @xor_to_xor5(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @xor_to_xor5(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-04-23 22:51:03 +08:00
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[A]], [[B]]
|
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%or1 = or i32 %a, %notb
|
|
|
|
%or2 = or i32 %nota, %b
|
|
|
|
%xor = xor i32 %or1, %or2
|
|
|
|
ret i32 %xor
|
|
|
|
}
|
|
|
|
|
|
|
|
; (a | ~b) ^ (b | ~a) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @xor_to_xor6(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @xor_to_xor6(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-06-30 15:37:41 +08:00
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[A]], [[B]]
|
2017-04-23 22:51:03 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%or1 = or i32 %a, %notb
|
|
|
|
%or2 = or i32 %b, %nota
|
|
|
|
%xor = xor i32 %or1, %or2
|
|
|
|
ret i32 %xor
|
|
|
|
}
|
|
|
|
|
|
|
|
; (~a | b) ^ (a | ~b) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @xor_to_xor7(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @xor_to_xor7(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
[PatternMatch] Stabilize the matching order of commutative matchers
Summary:
Currently, we
1. match `LHS` matcher to the `first` operand of binary operator,
2. and then match `RHS` matcher to the `second` operand of binary operator.
If that does not match, we swap the `LHS` and `RHS` matchers:
1. match `RHS` matcher to the `first` operand of binary operator,
2. and then match `LHS` matcher to the `second` operand of binary operator.
This works ok.
But it complicates writing of commutative matchers, where one would like to match
(`m_Value()`) the value on one side, and use (`m_Specific()`) it on the other side.
This is additionally complicated by the fact that `m_Specific()` stores the `Value *`,
not `Value **`, so it won't work at all out of the box.
The last problem is trivially solved by adding a new `m_c_Specific()` that stores the
`Value **`, not `Value *`. I'm choosing to add a new matcher, not change the existing
one because i guess all the current users are ok with existing behavior,
and this additional pointer indirection may have performance drawbacks.
Also, i'm storing pointer, not reference, because for some mysterious-to-me reason
it did not work with the reference.
The first one appears trivial, too.
Currently, we
1. match `LHS` matcher to the `first` operand of binary operator,
2. and then match `RHS` matcher to the `second` operand of binary operator.
If that does not match, we swap the ~~`LHS` and `RHS` matchers~~ **operands**:
1. match ~~`RHS`~~ **`LHS`** matcher to the ~~`first`~~ **`second`** operand of binary operator,
2. and then match ~~`LHS`~~ **`RHS`** matcher to the ~~`second`~ **`first`** operand of binary operator.
Surprisingly, `$ ninja check-llvm` still passes with this.
But i expect the bots will disagree..
The motivational unittest is included.
I'd like to use this in D45664.
Reviewers: spatel, craig.topper, arsenm, RKSimon
Reviewed By: craig.topper
Subscribers: xbolva00, wdng, llvm-commits
Differential Revision: https://reviews.llvm.org/D45828
llvm-svn: 331085
2018-04-28 05:23:20 +08:00
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[B]], [[A]]
|
2017-04-23 22:51:03 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%or1 = or i32 %a, %notb
|
|
|
|
%or2 = or i32 %nota, %b
|
|
|
|
%xor = xor i32 %or2, %or1
|
|
|
|
ret i32 %xor
|
|
|
|
}
|
|
|
|
|
|
|
|
; (~a | b) ^ (~b | a) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @xor_to_xor8(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @xor_to_xor8(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
[PatternMatch] Stabilize the matching order of commutative matchers
Summary:
Currently, we
1. match `LHS` matcher to the `first` operand of binary operator,
2. and then match `RHS` matcher to the `second` operand of binary operator.
If that does not match, we swap the `LHS` and `RHS` matchers:
1. match `RHS` matcher to the `first` operand of binary operator,
2. and then match `LHS` matcher to the `second` operand of binary operator.
This works ok.
But it complicates writing of commutative matchers, where one would like to match
(`m_Value()`) the value on one side, and use (`m_Specific()`) it on the other side.
This is additionally complicated by the fact that `m_Specific()` stores the `Value *`,
not `Value **`, so it won't work at all out of the box.
The last problem is trivially solved by adding a new `m_c_Specific()` that stores the
`Value **`, not `Value *`. I'm choosing to add a new matcher, not change the existing
one because i guess all the current users are ok with existing behavior,
and this additional pointer indirection may have performance drawbacks.
Also, i'm storing pointer, not reference, because for some mysterious-to-me reason
it did not work with the reference.
The first one appears trivial, too.
Currently, we
1. match `LHS` matcher to the `first` operand of binary operator,
2. and then match `RHS` matcher to the `second` operand of binary operator.
If that does not match, we swap the ~~`LHS` and `RHS` matchers~~ **operands**:
1. match ~~`RHS`~~ **`LHS`** matcher to the ~~`first`~~ **`second`** operand of binary operator,
2. and then match ~~`LHS`~~ **`RHS`** matcher to the ~~`second`~ **`first`** operand of binary operator.
Surprisingly, `$ ninja check-llvm` still passes with this.
But i expect the bots will disagree..
The motivational unittest is included.
I'd like to use this in D45664.
Reviewers: spatel, craig.topper, arsenm, RKSimon
Reviewed By: craig.topper
Subscribers: xbolva00, wdng, llvm-commits
Differential Revision: https://reviews.llvm.org/D45828
llvm-svn: 331085
2018-04-28 05:23:20 +08:00
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[B]], [[A]]
|
2017-04-23 22:51:03 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%or1 = or i32 %notb, %a
|
|
|
|
%or2 = or i32 %nota, %b
|
|
|
|
%xor = xor i32 %or2, %or1
|
|
|
|
ret i32 %xor
|
|
|
|
}
|
|
|
|
|
|
|
|
; (a & ~b) ^ (~a & b) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @xor_to_xor9(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @xor_to_xor9(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-04-23 22:51:03 +08:00
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[A]], [[B]]
|
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%and1 = and i32 %a, %notb
|
|
|
|
%and2 = and i32 %nota, %b
|
|
|
|
%xor = xor i32 %and1, %and2
|
|
|
|
ret i32 %xor
|
|
|
|
}
|
|
|
|
|
|
|
|
; (a & ~b) ^ (b & ~a) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @xor_to_xor10(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @xor_to_xor10(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-06-30 15:37:41 +08:00
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[A]], [[B]]
|
2017-04-23 22:51:03 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%and1 = and i32 %a, %notb
|
|
|
|
%and2 = and i32 %b, %nota
|
|
|
|
%xor = xor i32 %and1, %and2
|
|
|
|
ret i32 %xor
|
|
|
|
}
|
|
|
|
|
|
|
|
; (~a & b) ^ (a & ~b) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @xor_to_xor11(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @xor_to_xor11(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
[PatternMatch] Stabilize the matching order of commutative matchers
Summary:
Currently, we
1. match `LHS` matcher to the `first` operand of binary operator,
2. and then match `RHS` matcher to the `second` operand of binary operator.
If that does not match, we swap the `LHS` and `RHS` matchers:
1. match `RHS` matcher to the `first` operand of binary operator,
2. and then match `LHS` matcher to the `second` operand of binary operator.
This works ok.
But it complicates writing of commutative matchers, where one would like to match
(`m_Value()`) the value on one side, and use (`m_Specific()`) it on the other side.
This is additionally complicated by the fact that `m_Specific()` stores the `Value *`,
not `Value **`, so it won't work at all out of the box.
The last problem is trivially solved by adding a new `m_c_Specific()` that stores the
`Value **`, not `Value *`. I'm choosing to add a new matcher, not change the existing
one because i guess all the current users are ok with existing behavior,
and this additional pointer indirection may have performance drawbacks.
Also, i'm storing pointer, not reference, because for some mysterious-to-me reason
it did not work with the reference.
The first one appears trivial, too.
Currently, we
1. match `LHS` matcher to the `first` operand of binary operator,
2. and then match `RHS` matcher to the `second` operand of binary operator.
If that does not match, we swap the ~~`LHS` and `RHS` matchers~~ **operands**:
1. match ~~`RHS`~~ **`LHS`** matcher to the ~~`first`~~ **`second`** operand of binary operator,
2. and then match ~~`LHS`~~ **`RHS`** matcher to the ~~`second`~ **`first`** operand of binary operator.
Surprisingly, `$ ninja check-llvm` still passes with this.
But i expect the bots will disagree..
The motivational unittest is included.
I'd like to use this in D45664.
Reviewers: spatel, craig.topper, arsenm, RKSimon
Reviewed By: craig.topper
Subscribers: xbolva00, wdng, llvm-commits
Differential Revision: https://reviews.llvm.org/D45828
llvm-svn: 331085
2018-04-28 05:23:20 +08:00
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[B]], [[A]]
|
2017-04-23 22:51:03 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%and1 = and i32 %a, %notb
|
|
|
|
%and2 = and i32 %nota, %b
|
|
|
|
%xor = xor i32 %and2, %and1
|
|
|
|
ret i32 %xor
|
|
|
|
}
|
|
|
|
|
|
|
|
; (~a & b) ^ (~b & a) --> a ^ b
|
|
|
|
|
|
|
|
define i32 @xor_to_xor12(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @xor_to_xor12(
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
[PatternMatch] Stabilize the matching order of commutative matchers
Summary:
Currently, we
1. match `LHS` matcher to the `first` operand of binary operator,
2. and then match `RHS` matcher to the `second` operand of binary operator.
If that does not match, we swap the `LHS` and `RHS` matchers:
1. match `RHS` matcher to the `first` operand of binary operator,
2. and then match `LHS` matcher to the `second` operand of binary operator.
This works ok.
But it complicates writing of commutative matchers, where one would like to match
(`m_Value()`) the value on one side, and use (`m_Specific()`) it on the other side.
This is additionally complicated by the fact that `m_Specific()` stores the `Value *`,
not `Value **`, so it won't work at all out of the box.
The last problem is trivially solved by adding a new `m_c_Specific()` that stores the
`Value **`, not `Value *`. I'm choosing to add a new matcher, not change the existing
one because i guess all the current users are ok with existing behavior,
and this additional pointer indirection may have performance drawbacks.
Also, i'm storing pointer, not reference, because for some mysterious-to-me reason
it did not work with the reference.
The first one appears trivial, too.
Currently, we
1. match `LHS` matcher to the `first` operand of binary operator,
2. and then match `RHS` matcher to the `second` operand of binary operator.
If that does not match, we swap the ~~`LHS` and `RHS` matchers~~ **operands**:
1. match ~~`RHS`~~ **`LHS`** matcher to the ~~`first`~~ **`second`** operand of binary operator,
2. and then match ~~`LHS`~~ **`RHS`** matcher to the ~~`second`~ **`first`** operand of binary operator.
Surprisingly, `$ ninja check-llvm` still passes with this.
But i expect the bots will disagree..
The motivational unittest is included.
I'd like to use this in D45664.
Reviewers: spatel, craig.topper, arsenm, RKSimon
Reviewed By: craig.topper
Subscribers: xbolva00, wdng, llvm-commits
Differential Revision: https://reviews.llvm.org/D45828
llvm-svn: 331085
2018-04-28 05:23:20 +08:00
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[B]], [[A]]
|
2017-04-23 22:51:03 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%and1 = and i32 %notb, %a
|
|
|
|
%and2 = and i32 %nota, %b
|
|
|
|
%xor = xor i32 %and2, %and1
|
|
|
|
ret i32 %xor
|
|
|
|
}
|
|
|
|
|
2017-04-28 05:55:03 +08:00
|
|
|
; https://bugs.llvm.org/show_bug.cgi?id=32830
|
|
|
|
; Make sure we're matching operands correctly and not folding things wrongly.
|
|
|
|
|
|
|
|
define i64 @PR32830(i64 %a, i64 %b, i64 %c) {
|
|
|
|
; CHECK-LABEL: @PR32830(
|
2018-05-31 14:00:36 +08:00
|
|
|
; CHECK-NEXT: [[NOTA:%.*]] = xor i64 [[A:%.*]], -1
|
2018-04-27 05:13:09 +08:00
|
|
|
; CHECK-NEXT: [[NOTB:%.*]] = xor i64 [[B:%.*]], -1
|
2018-05-31 14:00:36 +08:00
|
|
|
; CHECK-NEXT: [[OR1:%.*]] = or i64 [[NOTB]], [[A]]
|
|
|
|
; CHECK-NEXT: [[OR2:%.*]] = or i64 [[NOTA]], [[C:%.*]]
|
|
|
|
; CHECK-NEXT: [[AND:%.*]] = and i64 [[OR1]], [[OR2]]
|
2017-04-28 05:55:03 +08:00
|
|
|
; CHECK-NEXT: ret i64 [[AND]]
|
|
|
|
;
|
|
|
|
%nota = xor i64 %a, -1
|
|
|
|
%notb = xor i64 %b, -1
|
|
|
|
%or1 = or i64 %notb, %a
|
|
|
|
%or2 = or i64 %nota, %c
|
|
|
|
%and = and i64 %or1, %or2
|
|
|
|
ret i64 %and
|
|
|
|
}
|
|
|
|
|
2017-06-22 13:20:39 +08:00
|
|
|
; (~a | b) & (~b | a) --> ~(a ^ b)
|
2017-06-30 17:11:50 +08:00
|
|
|
; TODO: this increases instruction count if the pieces have additional users
|
2017-06-22 13:20:39 +08:00
|
|
|
define i32 @and_to_nxor_multiuse(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @and_to_nxor_multiuse(
|
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[NOTA:%.*]] = xor i32 [[A]], -1
|
|
|
|
; CHECK-NEXT: [[NOTB:%.*]] = xor i32 [[B]], -1
|
|
|
|
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[NOTA]], [[B]]
|
|
|
|
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[NOTB]], [[A]]
|
2017-06-23 00:12:02 +08:00
|
|
|
; CHECK-NEXT: [[AND:%.*]] = and i32 [[OR1]], [[OR2]]
|
2017-06-22 13:20:39 +08:00
|
|
|
; CHECK-NEXT: [[MUL1:%.*]] = mul i32 [[OR1]], [[OR2]]
|
|
|
|
; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL1]], [[AND]]
|
|
|
|
; CHECK-NEXT: ret i32 [[MUL2]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%or1 = or i32 %nota, %b
|
|
|
|
%or2 = or i32 %notb, %a
|
|
|
|
%and = and i32 %or1, %or2
|
|
|
|
%mul1 = mul i32 %or1, %or2 ; here to increase the use count of the inputs to the and
|
|
|
|
%mul2 = mul i32 %mul1, %and
|
|
|
|
ret i32 %mul2
|
|
|
|
}
|
|
|
|
|
|
|
|
; (a & b) | ~(a | b) --> ~(a ^ b)
|
2017-06-30 17:11:50 +08:00
|
|
|
; TODO: this increases instruction count if the pieces have additional users
|
2017-06-22 13:20:39 +08:00
|
|
|
define i32 @or_to_nxor_multiuse(i32 %a, i32 %b) {
|
|
|
|
; CHECK-LABEL: @or_to_nxor_multiuse(
|
|
|
|
; CHECK-NEXT: [[AND:%.*]] = and i32 [[A:%.*]], [[B:%.*]]
|
|
|
|
; CHECK-NEXT: [[OR:%.*]] = or i32 [[A]], [[B]]
|
|
|
|
; CHECK-NEXT: [[NOTOR:%.*]] = xor i32 [[OR]], -1
|
2017-06-23 00:12:02 +08:00
|
|
|
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[AND]], [[NOTOR]]
|
2017-06-22 13:20:39 +08:00
|
|
|
; CHECK-NEXT: [[MUL1:%.*]] = mul i32 [[AND]], [[NOTOR]]
|
|
|
|
; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL1]], [[OR2]]
|
|
|
|
; CHECK-NEXT: ret i32 [[MUL2]]
|
|
|
|
;
|
|
|
|
%and = and i32 %a, %b
|
|
|
|
%or = or i32 %a, %b
|
|
|
|
%notor = xor i32 %or, -1
|
|
|
|
%or2 = or i32 %and, %notor
|
|
|
|
%mul1 = mul i32 %and, %notor ; here to increase the use count of the inputs to the or
|
|
|
|
%mul2 = mul i32 %mul1, %or2
|
|
|
|
ret i32 %mul2
|
|
|
|
}
|
2017-06-30 15:37:42 +08:00
|
|
|
|
|
|
|
; (a | b) ^ (~a | ~b) --> ~(a ^ b)
|
|
|
|
define i32 @xor_to_xnor1(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @xor_to_xnor1(
|
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-07-02 09:15:51 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[A]], [[B]]
|
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[TMP1]], -1
|
2017-06-30 15:37:42 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%or1 = or i32 %a, %b
|
|
|
|
%or2 = or i32 %nota, %notb
|
|
|
|
%xor = xor i32 %or1, %or2
|
|
|
|
ret i32 %xor
|
|
|
|
}
|
|
|
|
|
|
|
|
; (a | b) ^ (~b | ~a) --> ~(a ^ b)
|
|
|
|
define i32 @xor_to_xnor2(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @xor_to_xnor2(
|
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-07-02 09:15:51 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[A]], [[B]]
|
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[TMP1]], -1
|
2017-06-30 15:37:42 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%or1 = or i32 %a, %b
|
|
|
|
%or2 = or i32 %notb, %nota
|
|
|
|
%xor = xor i32 %or1, %or2
|
|
|
|
ret i32 %xor
|
|
|
|
}
|
|
|
|
|
|
|
|
; (~a | ~b) ^ (a | b) --> ~(a ^ b)
|
|
|
|
define i32 @xor_to_xnor3(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @xor_to_xnor3(
|
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-07-02 09:15:51 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[A]], [[B]]
|
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[TMP1]], -1
|
2017-06-30 15:37:42 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%or1 = or i32 %nota, %notb
|
|
|
|
%or2 = or i32 %a, %b
|
|
|
|
%xor = xor i32 %or1, %or2
|
|
|
|
ret i32 %xor
|
|
|
|
}
|
|
|
|
|
|
|
|
; (~a | ~b) ^ (b | a) --> ~(a ^ b)
|
|
|
|
define i32 @xor_to_xnor4(float %fa, float %fb) {
|
|
|
|
; CHECK-LABEL: @xor_to_xnor4(
|
|
|
|
; CHECK-NEXT: [[A:%.*]] = fptosi float [[FA:%.*]] to i32
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fptosi float [[FB:%.*]] to i32
|
2017-07-02 09:15:51 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[B]], [[A]]
|
|
|
|
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[TMP1]], -1
|
2017-06-30 15:37:42 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[XOR]]
|
|
|
|
;
|
|
|
|
%a = fptosi float %fa to i32
|
|
|
|
%b = fptosi float %fb to i32
|
|
|
|
%nota = xor i32 %a, -1
|
|
|
|
%notb = xor i32 %b, -1
|
|
|
|
%or1 = or i32 %nota, %notb
|
|
|
|
%or2 = or i32 %b, %a
|
|
|
|
%xor = xor i32 %or1, %or2
|
|
|
|
ret i32 %xor
|
|
|
|
}
|