2020-08-20 00:07:28 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
2020-02-21 05:42:42 +08:00
|
|
|
; RUN: opt -instcombine -instcombine-infinite-loop-threshold=2 -S < %s | FileCheck %s
|
2019-04-17 12:52:47 +08:00
|
|
|
|
|
|
|
; <rdar://problem/8606771>
|
|
|
|
define i32 @main(i32 %argc) {
|
|
|
|
; CHECK-LABEL: @main(
|
2020-08-20 00:07:28 +08:00
|
|
|
; CHECK-NEXT: [[T3151:%.*]] = trunc i32 [[ARGC:%.*]] to i8
|
[InstCombine] canonicalize 'not' ops before logical shifts
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
2020-08-22 21:38:13 +08:00
|
|
|
; CHECK-NEXT: [[T3163:%.*]] = xor i8 [[T3151]], -1
|
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = shl i8 [[T3163]], 5
|
|
|
|
; CHECK-NEXT: [[T4127:%.*]] = and i8 [[TMP1]], 64
|
2020-08-20 00:07:28 +08:00
|
|
|
; CHECK-NEXT: [[T4086:%.*]] = zext i8 [[T4127]] to i32
|
|
|
|
; CHECK-NEXT: ret i32 [[T4086]]
|
2019-04-17 12:52:47 +08:00
|
|
|
;
|
2020-08-20 00:07:28 +08:00
|
|
|
%t3151 = trunc i32 %argc to i8
|
|
|
|
%t3161 = or i8 %t3151, -17
|
|
|
|
%t3162 = and i8 %t3151, 122
|
|
|
|
%t3163 = xor i8 %t3162, -17
|
|
|
|
%t4114 = shl i8 %t3163, 6
|
|
|
|
%t4115 = xor i8 %t4114, %t3163
|
|
|
|
%t4120 = xor i8 %t3161, %t4115
|
|
|
|
%t4126 = lshr i8 %t4120, 7
|
|
|
|
%t4127 = mul i8 %t4126, 64
|
|
|
|
%t4086 = zext i8 %t4127 to i32
|
|
|
|
ret i32 %t4086
|
2019-04-17 12:52:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
; rdar://8739316
|
|
|
|
define i8 @foo(i8 %arg, i8 %arg1) {
|
|
|
|
; CHECK-LABEL: @foo(
|
2020-08-20 00:07:28 +08:00
|
|
|
; CHECK-NEXT: [[T:%.*]] = shl i8 [[ARG:%.*]], 7
|
|
|
|
; CHECK-NEXT: [[T2:%.*]] = and i8 [[ARG1:%.*]], 84
|
|
|
|
; CHECK-NEXT: [[T3:%.*]] = and i8 [[ARG1]], -118
|
|
|
|
; CHECK-NEXT: [[T4:%.*]] = and i8 [[ARG1]], 33
|
|
|
|
; CHECK-NEXT: [[T5:%.*]] = sub nsw i8 40, [[T2]]
|
|
|
|
; CHECK-NEXT: [[T6:%.*]] = and i8 [[T5]], 84
|
|
|
|
; CHECK-NEXT: [[T7:%.*]] = or i8 [[T4]], [[T6]]
|
|
|
|
; CHECK-NEXT: [[T8:%.*]] = xor i8 [[T]], [[T3]]
|
|
|
|
; CHECK-NEXT: [[T9:%.*]] = or i8 [[T7]], [[T8]]
|
|
|
|
; CHECK-NEXT: [[T10:%.*]] = lshr i8 [[T8]], 7
|
|
|
|
; CHECK-NEXT: [[T11:%.*]] = shl nuw nsw i8 [[T10]], 5
|
|
|
|
; CHECK-NEXT: [[T12:%.*]] = xor i8 [[T11]], [[T9]]
|
|
|
|
; CHECK-NEXT: ret i8 [[T12]]
|
2019-04-17 12:52:47 +08:00
|
|
|
;
|
2020-08-20 00:07:28 +08:00
|
|
|
%t = shl i8 %arg, 7
|
|
|
|
%t2 = and i8 %arg1, 84
|
|
|
|
%t3 = and i8 %arg1, -118
|
|
|
|
%t4 = and i8 %arg1, 33
|
|
|
|
%t5 = sub i8 -88, %t2
|
|
|
|
%t6 = and i8 %t5, 84
|
|
|
|
%t7 = or i8 %t4, %t6
|
|
|
|
%t8 = xor i8 %t, %t3
|
|
|
|
%t9 = or i8 %t7, %t8
|
|
|
|
%t10 = lshr i8 %t8, 7
|
|
|
|
%t11 = shl i8 %t10, 5
|
|
|
|
%t12 = xor i8 %t11, %t9
|
|
|
|
ret i8 %t12
|
2019-04-17 12:52:47 +08:00
|
|
|
}
|