2019-09-04 20:18:53 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
2022-02-04 20:39:52 +08:00
|
|
|
; RUN: opt -passes=instcombine -S < %s | FileCheck %s
|
2019-09-04 20:18:53 +08:00
|
|
|
|
|
|
|
declare void @use(i32)
|
|
|
|
|
|
|
|
define i32 @sub_to_xor(i32 %x, i32 %y) {
|
|
|
|
; CHECK-LABEL: @sub_to_xor(
|
[InstCombine] Fold sub (and A, B) (or A, B)) to neg (xor A, B)
Summary:
```
Name: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
%or = or i32 %y, %x
%and = and i32 %x, %y
%sub = sub i32 %and, %or
=>
%sub1 = xor i32 %x, %y
%sub = sub i32 0, %sub1
Optimization: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
Done: 1
Optimization is correct!
```
https://rise4fun.com/Alive/VI6
Found by @lebedev.ri. Also author of the proof.
Reviewers: lebedev.ri, spatel
Reviewed By: lebedev.ri
Subscribers: llvm-commits, lebedev.ri
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67155
llvm-svn: 370934
2019-09-05 01:30:53 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
|
|
|
|
; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
|
2019-09-04 20:18:53 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[SUB]]
|
|
|
|
;
|
|
|
|
%or = or i32 %x, %y
|
|
|
|
%and = and i32 %x, %y
|
|
|
|
%sub = sub i32 %and, %or
|
|
|
|
ret i32 %sub
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @sub_to_xor_extra_use_sub(i32 %x, i32 %y) {
|
|
|
|
; CHECK-LABEL: @sub_to_xor_extra_use_sub(
|
[InstCombine] Fold sub (and A, B) (or A, B)) to neg (xor A, B)
Summary:
```
Name: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
%or = or i32 %y, %x
%and = and i32 %x, %y
%sub = sub i32 %and, %or
=>
%sub1 = xor i32 %x, %y
%sub = sub i32 0, %sub1
Optimization: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
Done: 1
Optimization is correct!
```
https://rise4fun.com/Alive/VI6
Found by @lebedev.ri. Also author of the proof.
Reviewers: lebedev.ri, spatel
Reviewed By: lebedev.ri
Subscribers: llvm-commits, lebedev.ri
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67155
llvm-svn: 370934
2019-09-05 01:30:53 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
|
|
|
|
; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
|
2019-09-04 20:18:53 +08:00
|
|
|
; CHECK-NEXT: call void @use(i32 [[SUB]])
|
|
|
|
; CHECK-NEXT: ret i32 [[SUB]]
|
|
|
|
;
|
|
|
|
%or = or i32 %x, %y
|
|
|
|
%and = and i32 %x, %y
|
|
|
|
%sub = sub i32 %and, %or
|
|
|
|
call void @use(i32 %sub)
|
|
|
|
ret i32 %sub
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @sub_to_xor_extra_use_and(i32 %x, i32 %y) {
|
|
|
|
; CHECK-LABEL: @sub_to_xor_extra_use_and(
|
[InstCombine] Fold sub (and A, B) (or A, B)) to neg (xor A, B)
Summary:
```
Name: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
%or = or i32 %y, %x
%and = and i32 %x, %y
%sub = sub i32 %and, %or
=>
%sub1 = xor i32 %x, %y
%sub = sub i32 0, %sub1
Optimization: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
Done: 1
Optimization is correct!
```
https://rise4fun.com/Alive/VI6
Found by @lebedev.ri. Also author of the proof.
Reviewers: lebedev.ri, spatel
Reviewed By: lebedev.ri
Subscribers: llvm-commits, lebedev.ri
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67155
llvm-svn: 370934
2019-09-05 01:30:53 +08:00
|
|
|
; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
|
2019-09-04 20:18:53 +08:00
|
|
|
; CHECK-NEXT: call void @use(i32 [[AND]])
|
[InstCombine] Fold sub (and A, B) (or A, B)) to neg (xor A, B)
Summary:
```
Name: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
%or = or i32 %y, %x
%and = and i32 %x, %y
%sub = sub i32 %and, %or
=>
%sub1 = xor i32 %x, %y
%sub = sub i32 0, %sub1
Optimization: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
Done: 1
Optimization is correct!
```
https://rise4fun.com/Alive/VI6
Found by @lebedev.ri. Also author of the proof.
Reviewers: lebedev.ri, spatel
Reviewed By: lebedev.ri
Subscribers: llvm-commits, lebedev.ri
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67155
llvm-svn: 370934
2019-09-05 01:30:53 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[X]], [[Y]]
|
|
|
|
; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
|
2019-09-04 20:18:53 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[SUB]]
|
|
|
|
;
|
|
|
|
%or = or i32 %x, %y
|
|
|
|
%and = and i32 %x, %y
|
|
|
|
call void @use(i32 %and)
|
|
|
|
%sub = sub i32 %and, %or
|
|
|
|
ret i32 %sub
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @sub_to_xor_extra_use_or(i32 %x, i32 %y) {
|
|
|
|
; CHECK-LABEL: @sub_to_xor_extra_use_or(
|
|
|
|
; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
|
|
|
|
; CHECK-NEXT: call void @use(i32 [[OR]])
|
[InstCombine] Fold sub (and A, B) (or A, B)) to neg (xor A, B)
Summary:
```
Name: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
%or = or i32 %y, %x
%and = and i32 %x, %y
%sub = sub i32 %and, %or
=>
%sub1 = xor i32 %x, %y
%sub = sub i32 0, %sub1
Optimization: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
Done: 1
Optimization is correct!
```
https://rise4fun.com/Alive/VI6
Found by @lebedev.ri. Also author of the proof.
Reviewers: lebedev.ri, spatel
Reviewed By: lebedev.ri
Subscribers: llvm-commits, lebedev.ri
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67155
llvm-svn: 370934
2019-09-05 01:30:53 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[X]], [[Y]]
|
|
|
|
; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
|
2019-09-04 20:18:53 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[SUB]]
|
|
|
|
;
|
|
|
|
%or = or i32 %x, %y
|
|
|
|
call void @use(i32 %or)
|
|
|
|
%and = and i32 %x, %y
|
|
|
|
%sub = sub i32 %and, %or
|
|
|
|
ret i32 %sub
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @sub_to_xor_or_commuted(i32 %x, i32 %y) {
|
|
|
|
; CHECK-LABEL: @sub_to_xor_or_commuted(
|
[InstCombine] Fold sub (and A, B) (or A, B)) to neg (xor A, B)
Summary:
```
Name: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
%or = or i32 %y, %x
%and = and i32 %x, %y
%sub = sub i32 %and, %or
=>
%sub1 = xor i32 %x, %y
%sub = sub i32 0, %sub1
Optimization: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
Done: 1
Optimization is correct!
```
https://rise4fun.com/Alive/VI6
Found by @lebedev.ri. Also author of the proof.
Reviewers: lebedev.ri, spatel
Reviewed By: lebedev.ri
Subscribers: llvm-commits, lebedev.ri
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67155
llvm-svn: 370934
2019-09-05 01:30:53 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
|
|
|
|
; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
|
2019-09-04 20:18:53 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[SUB]]
|
|
|
|
;
|
|
|
|
%or = or i32 %y, %x
|
|
|
|
%and = and i32 %x, %y
|
|
|
|
%sub = sub i32 %and, %or
|
|
|
|
ret i32 %sub
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @sub_to_xor_and_commuted(i32 %x, i32 %y) {
|
|
|
|
; CHECK-LABEL: @sub_to_xor_and_commuted(
|
[InstCombine] Fold sub (and A, B) (or A, B)) to neg (xor A, B)
Summary:
```
Name: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
%or = or i32 %y, %x
%and = and i32 %x, %y
%sub = sub i32 %and, %or
=>
%sub1 = xor i32 %x, %y
%sub = sub i32 0, %sub1
Optimization: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
Done: 1
Optimization is correct!
```
https://rise4fun.com/Alive/VI6
Found by @lebedev.ri. Also author of the proof.
Reviewers: lebedev.ri, spatel
Reviewed By: lebedev.ri
Subscribers: llvm-commits, lebedev.ri
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67155
llvm-svn: 370934
2019-09-05 01:30:53 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[Y:%.*]], [[X:%.*]]
|
|
|
|
; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
|
2019-09-04 20:18:53 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[SUB]]
|
|
|
|
;
|
|
|
|
%or = or i32 %x, %y
|
|
|
|
%and = and i32 %y, %x
|
|
|
|
%sub = sub i32 %and, %or
|
|
|
|
ret i32 %sub
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x i32> @sub_to_xor_vec(<2 x i32> %x, <2 x i32> %y) {
|
|
|
|
; CHECK-LABEL: @sub_to_xor_vec(
|
[InstCombine] Fold sub (and A, B) (or A, B)) to neg (xor A, B)
Summary:
```
Name: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
%or = or i32 %y, %x
%and = and i32 %x, %y
%sub = sub i32 %and, %or
=>
%sub1 = xor i32 %x, %y
%sub = sub i32 0, %sub1
Optimization: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
Done: 1
Optimization is correct!
```
https://rise4fun.com/Alive/VI6
Found by @lebedev.ri. Also author of the proof.
Reviewers: lebedev.ri, spatel
Reviewed By: lebedev.ri
Subscribers: llvm-commits, lebedev.ri
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67155
llvm-svn: 370934
2019-09-05 01:30:53 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i32> [[Y:%.*]], [[X:%.*]]
|
|
|
|
; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> zeroinitializer, [[TMP1]]
|
2019-09-04 20:18:53 +08:00
|
|
|
; CHECK-NEXT: ret <2 x i32> [[SUB]]
|
|
|
|
;
|
|
|
|
%or = or <2 x i32> %x, %y
|
|
|
|
%and = and <2 x i32> %y, %x
|
2019-09-04 20:43:14 +08:00
|
|
|
%sub = sub <2 x i32> %and, %or
|
2019-09-04 20:18:53 +08:00
|
|
|
ret <2 x i32> %sub
|
|
|
|
}
|
2019-09-04 20:46:25 +08:00
|
|
|
|
|
|
|
; Negative tests
|
|
|
|
|
|
|
|
define i32 @sub_to_xor_extra_use_and_or(i32 %x, i32 %y) {
|
|
|
|
; CHECK-LABEL: @sub_to_xor_extra_use_and_or(
|
|
|
|
; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
|
|
|
|
; CHECK-NEXT: call void @use(i32 [[OR]])
|
|
|
|
; CHECK-NEXT: [[AND:%.*]] = and i32 [[X]], [[Y]]
|
|
|
|
; CHECK-NEXT: call void @use(i32 [[AND]])
|
|
|
|
; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[AND]], [[OR]]
|
|
|
|
; CHECK-NEXT: ret i32 [[SUB]]
|
|
|
|
;
|
|
|
|
%or = or i32 %x, %y
|
|
|
|
call void @use(i32 %or)
|
|
|
|
%and = and i32 %x, %y
|
|
|
|
call void @use(i32 %and)
|
|
|
|
%sub = sub i32 %and, %or
|
|
|
|
ret i32 %sub
|
|
|
|
}
|