mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 12:43:36 +01:00
8998944672
This reverses the existing transform that would uniformly canonicalize any 'xor' after any shift. In the case of logical shifts, that turns a 'not' into an arbitrary 'xor' with constant, and that's probably not as good for analysis, SCEV, or codegen. The SCEV motivating case is discussed in: http://bugs.llvm.org/PR47136 There's an analysis motivating case at: http://bugs.llvm.org/PR38781 I did draft a patch that would do the same for 'ashr' but that's questionable because it's just swapping the position of a 'not' and uncovers at least 2 missing folds that we would probably need to deal with as preliminary steps. Alive proofs: https://rise4fun.com/Alive/BBV Name: shift right of 'not' Pre: C2 == (-1 u>> C1) %a = lshr i8 %x, C1 %r = xor i8 %a, C2 => %n = xor i8 %x, -1 %r = lshr i8 %n, C1 Name: shift left of 'not' Pre: C2 == (-1 << C1) %a = shl i8 %x, C1 %r = xor i8 %a, C2 => %n = xor i8 %x, -1 %r = shl i8 %n, C1 Name: ashr of 'not' %a = ashr i8 %x, C1 %r = xor i8 %a, -1 => %n = xor i8 %x, -1 %r = ashr i8 %n, C1 Differential Revision: https://reviews.llvm.org/D86243
43 lines
1.2 KiB
LLVM
43 lines
1.2 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
|
|
|
; (x&z) ^ (y&z) -> (x^y)&z
|
|
define i32 @test1(i32 %x, i32 %y, i32 %z) {
|
|
; CHECK-LABEL: @test1(
|
|
; CHECK-NEXT: [[T61:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
|
|
; CHECK-NEXT: [[T7:%.*]] = and i32 [[T61]], [[Z:%.*]]
|
|
; CHECK-NEXT: ret i32 [[T7]]
|
|
;
|
|
%t3 = and i32 %z, %x
|
|
%t6 = and i32 %z, %y
|
|
%t7 = xor i32 %t3, %t6
|
|
ret i32 %t7
|
|
}
|
|
|
|
; (x & y) ^ (x|y) -> x^y
|
|
define i32 @test2(i32 %x, i32 %y, i32 %z) {
|
|
; CHECK-LABEL: @test2(
|
|
; CHECK-NEXT: [[T7:%.*]] = xor i32 [[Y:%.*]], [[X:%.*]]
|
|
; CHECK-NEXT: ret i32 [[T7]]
|
|
;
|
|
%t3 = and i32 %y, %x
|
|
%t6 = or i32 %y, %x
|
|
%t7 = xor i32 %t3, %t6
|
|
ret i32 %t7
|
|
}
|
|
|
|
define i32 @PR38761(i32 %a, i32 %b) {
|
|
; CHECK-LABEL: @PR38761(
|
|
; CHECK-NEXT: [[B_LOBIT_NOT1_DEMORGAN:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
|
|
; CHECK-NEXT: [[B_LOBIT_NOT1:%.*]] = xor i32 [[B_LOBIT_NOT1_DEMORGAN]], -1
|
|
; CHECK-NEXT: [[AND:%.*]] = lshr i32 [[B_LOBIT_NOT1]], 31
|
|
; CHECK-NEXT: ret i32 [[AND]]
|
|
;
|
|
%a.lobit = lshr i32 %a, 31
|
|
%a.lobit.not = xor i32 %a.lobit, 1
|
|
%b.lobit = lshr i32 %b, 31
|
|
%b.lobit.not = xor i32 %b.lobit, 1
|
|
%and = and i32 %b.lobit.not, %a.lobit.not
|
|
ret i32 %and
|
|
}
|