1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
11 ; Most basic positive test
12 define i8 @t0(i8 %x, i8 %y) {
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]]
18 %not_x = xor i8 %x, -1
19 %ashr = ashr i8 %not_x, %y
22 ; 'exact'-ness isn't preserved!
23 define i8 @t1(i8 %x, i8 %y) {
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]]
29 %not_x = xor i8 %x, -1
30 %ashr = ashr exact i8 %not_x, %y
34 define <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]], <i8 -1, i8 -1>
38 ; CHECK-NEXT: ret <2 x i8> [[ASHR]]
40 %not_x = xor <2 x i8> %x, <i8 -1, i8 -1>
41 %ashr = ashr <2 x i8> %not_x, %y
44 ; Note that we must sanitize poison elts of -1 constant to -1 or 0.
45 define <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]], <i8 -1, i8 -1>
49 ; CHECK-NEXT: ret <2 x i8> [[ASHR]]
51 %not_x = xor <2 x i8> %x, <i8 -1, i8 poison>
52 %ashr = ashr <2 x i8> %not_x, %y
56 ; Extra use prevents the fold.
57 define i8 @n4(i8 %x, i8 %y) {
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]]
64 %not_x = xor i8 %x, -1
65 call void @use8(i8 %not_x)
66 %ashr = ashr i8 %not_x, %y