xref: /llvm-project/llvm/test/Transforms/InstCombine/hoist-not-from-ashr-operand.ll (revision 38fffa630ee80163dc65e759392ad29798905679)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3
4; Transform
5;   (~x) a>> y
6; into:
7;   ~(x a>> y)
8
9declare void @use8(i8)
10
11; Most basic positive test
12define i8 @t0(i8 %x, i8 %y) {
13; CHECK-LABEL: @t0(
14; CHECK-NEXT:    [[NOT_X_NOT:%.*]] = ashr i8 [[X:%.*]], [[Y:%.*]]
15; CHECK-NEXT:    [[ASHR:%.*]] = xor i8 [[NOT_X_NOT]], -1
16; CHECK-NEXT:    ret i8 [[ASHR]]
17;
18  %not_x = xor i8 %x, -1
19  %ashr = ashr i8 %not_x, %y
20  ret i8 %ashr
21}
22; 'exact'-ness isn't preserved!
23define i8 @t1(i8 %x, i8 %y) {
24; CHECK-LABEL: @t1(
25; CHECK-NEXT:    [[NOT_X_NOT:%.*]] = ashr i8 [[X:%.*]], [[Y:%.*]]
26; CHECK-NEXT:    [[ASHR:%.*]] = xor i8 [[NOT_X_NOT]], -1
27; CHECK-NEXT:    ret i8 [[ASHR]]
28;
29  %not_x = xor i8 %x, -1
30  %ashr = ashr exact i8 %not_x, %y
31  ret i8 %ashr
32}
33; Basic vector test
34define <2 x i8> @t2_vec(<2 x i8> %x, <2 x i8> %y) {
35; CHECK-LABEL: @t2_vec(
36; CHECK-NEXT:    [[NOT_X_NOT:%.*]] = ashr <2 x i8> [[X:%.*]], [[Y:%.*]]
37; CHECK-NEXT:    [[ASHR:%.*]] = xor <2 x i8> [[NOT_X_NOT]], splat (i8 -1)
38; CHECK-NEXT:    ret <2 x i8> [[ASHR]]
39;
40  %not_x = xor <2 x i8> %x, <i8 -1, i8 -1>
41  %ashr = ashr <2 x i8> %not_x, %y
42  ret <2 x i8> %ashr
43}
44; Note that we must sanitize poison elts of -1 constant to -1 or 0.
45define <2 x i8> @t3_vec_poison(<2 x i8> %x, <2 x i8> %y) {
46; CHECK-LABEL: @t3_vec_poison(
47; CHECK-NEXT:    [[NOT_X_NOT:%.*]] = ashr <2 x i8> [[X:%.*]], [[Y:%.*]]
48; CHECK-NEXT:    [[ASHR:%.*]] = xor <2 x i8> [[NOT_X_NOT]], splat (i8 -1)
49; CHECK-NEXT:    ret <2 x i8> [[ASHR]]
50;
51  %not_x = xor <2 x i8> %x, <i8 -1, i8 poison>
52  %ashr = ashr <2 x i8> %not_x, %y
53  ret <2 x i8> %ashr
54}
55
56; Extra use prevents the fold.
57define i8 @n4(i8 %x, i8 %y) {
58; CHECK-LABEL: @n4(
59; CHECK-NEXT:    [[NOT_X:%.*]] = xor i8 [[X:%.*]], -1
60; CHECK-NEXT:    call void @use8(i8 [[NOT_X]])
61; CHECK-NEXT:    [[ASHR:%.*]] = ashr i8 [[NOT_X]], [[Y:%.*]]
62; CHECK-NEXT:    ret i8 [[ASHR]]
63;
64  %not_x = xor i8 %x, -1
65  call void @use8(i8 %not_x)
66  %ashr = ashr i8 %not_x, %y
67  ret i8 %ashr
68}
69