1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00
llvm-mirror/test/Transforms/InstCombine/sub-xor-or-neg-and.ll
David Bolvansky a06a2b5f16 [InstCombine] sub(xor(x, y), or(x, y)) -> neg(and(x, y))
Summary:
```
Name: sub(xor(x, y), or(x, y)) -> neg(and(x, y))
%or = or i32 %y, %x
%xor = xor i32 %x, %y
%sub = sub i32 %xor, %or
  =>
%sub1 = and i32 %x, %y
%sub = sub i32 0, %sub1

Optimization: sub(xor(x, y), or(x, y)) -> neg(and(x, y))
Done: 1
Optimization is correct!
```

https://rise4fun.com/Alive/8OI

Reviewers: lebedev.ri

Reviewed By: lebedev.ri

Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 370945
2019-09-04 18:03:21 +00:00

116 lines
3.3 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -instcombine -S < %s | FileCheck %s
declare void @use(i32)
define i32 @sub_to_and(i32 %x, i32 %y) {
; CHECK-LABEL: @sub_to_and(
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
; CHECK-NEXT: ret i32 [[SUB]]
;
%or = or i32 %x, %y
%xor = xor i32 %x, %y
%sub = sub i32 %xor, %or
ret i32 %sub
}
define i32 @sub_to_and_extra_use_sub(i32 %x, i32 %y) {
; CHECK-LABEL: @sub_to_and_extra_use_sub(
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
; CHECK-NEXT: call void @use(i32 [[SUB]])
; CHECK-NEXT: ret i32 [[SUB]]
;
%or = or i32 %x, %y
%xor = xor i32 %x, %y
%sub = sub i32 %xor, %or
call void @use(i32 %sub)
ret i32 %sub
}
define i32 @sub_to_and_extra_use_and(i32 %x, i32 %y) {
; CHECK-LABEL: @sub_to_and_extra_use_and(
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: call void @use(i32 [[XOR]])
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X]], [[Y]]
; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
; CHECK-NEXT: ret i32 [[SUB]]
;
%or = or i32 %x, %y
%xor = xor i32 %x, %y
call void @use(i32 %xor)
%sub = sub i32 %xor, %or
ret i32 %sub
}
define i32 @sub_to_and_extra_use_or(i32 %x, i32 %y) {
; CHECK-LABEL: @sub_to_and_extra_use_or(
; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: call void @use(i32 [[OR]])
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X]], [[Y]]
; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
; CHECK-NEXT: ret i32 [[SUB]]
;
%or = or i32 %x, %y
call void @use(i32 %or)
%xor = xor i32 %x, %y
%sub = sub i32 %xor, %or
ret i32 %sub
}
define i32 @sub_to_and_or_commuted(i32 %x, i32 %y) {
; CHECK-LABEL: @sub_to_and_or_commuted(
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
; CHECK-NEXT: ret i32 [[SUB]]
;
%or = or i32 %y, %x
%xor = xor i32 %x, %y
%sub = sub i32 %xor, %or
ret i32 %sub
}
define i32 @sub_to_and_and_commuted(i32 %x, i32 %y) {
; CHECK-LABEL: @sub_to_and_and_commuted(
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
; CHECK-NEXT: ret i32 [[SUB]]
;
%or = or i32 %x, %y
%xor = xor i32 %y, %x
%sub = sub i32 %xor, %or
ret i32 %sub
}
define <2 x i32> @sub_to_and_vec(<2 x i32> %x, <2 x i32> %y) {
; CHECK-LABEL: @sub_to_and_vec(
; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> zeroinitializer, [[TMP1]]
; CHECK-NEXT: ret <2 x i32> [[SUB]]
;
%or = or <2 x i32> %x, %y
%xor = xor <2 x i32> %y, %x
%sub = sub <2 x i32> %xor, %or
ret <2 x i32> %sub
}
; Negative tests
define i32 @sub_to_and_extra_use_and_or(i32 %x, i32 %y) {
; CHECK-LABEL: @sub_to_and_extra_use_and_or(
; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: call void @use(i32 [[OR]])
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X]], [[Y]]
; CHECK-NEXT: call void @use(i32 [[XOR]])
; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[XOR]], [[OR]]
; CHECK-NEXT: ret i32 [[SUB]]
;
%or = or i32 %x, %y
call void @use(i32 %or)
%xor = xor i32 %x, %y
call void @use(i32 %xor)
%sub = sub i32 %xor, %or
ret i32 %sub
}