1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
; 'Negate' is considered less complex than a normal binop, so the xor should have the binop as the first operand.
define i8 @neg(i8 %x) {
; CHECK-LABEL: @neg(
; CHECK-NEXT: [[BO:%.*]] = udiv i8 [[X:%.*]], 42
; CHECK-NEXT: [[NEGX:%.*]] = sub i8 0, [[X]]
; CHECK-NEXT: [[R:%.*]] = xor i8 [[BO]], [[NEGX]]
; CHECK-NEXT: ret i8 [[R]]
;
%bo = udiv i8 %x, 42
%negx = sub i8 0, %x
%r = xor i8 %negx, %bo
ret i8 %r
}
define <2 x i8> @neg_vec(<2 x i8> %x) {
; CHECK-LABEL: @neg_vec(
; CHECK-NEXT: [[BO:%.*]] = udiv <2 x i8> [[X:%.*]], <i8 42, i8 -42>
; CHECK-NEXT: [[NEGX:%.*]] = sub <2 x i8> zeroinitializer, [[X]]
; CHECK-NEXT: [[R:%.*]] = xor <2 x i8> [[BO]], [[NEGX]]
; CHECK-NEXT: ret <2 x i8> [[R]]
;
%bo = udiv <2 x i8> %x, <i8 42, i8 -42>
%negx = sub <2 x i8> <i8 0, i8 0>, %x
%r = xor <2 x i8> %negx, %bo
ret <2 x i8> %r
}
define <2 x i8> @neg_vec_undef(<2 x i8> %x) {
; CHECK-LABEL: @neg_vec_undef(
; CHECK-NEXT: [[BO:%.*]] = udiv <2 x i8> [[X:%.*]], <i8 42, i8 -42>
; CHECK-NEXT: [[NEGX:%.*]] = sub <2 x i8> <i8 0, i8 undef>, [[X]]
; CHECK-NEXT: [[R:%.*]] = xor <2 x i8> [[BO]], [[NEGX]]
; CHECK-NEXT: ret <2 x i8> [[R]]
;
%bo = udiv <2 x i8> %x, <i8 42, i8 -42>
%negx = sub <2 x i8> <i8 0, i8 undef>, %x
%r = xor <2 x i8> %negx, %bo
ret <2 x i8> %r
}
; 'Not' is considered less complex than a normal binop, so the mul should have the binop as the first operand.
define i8 @not(i8 %x) {
; CHECK-LABEL: @not(
; CHECK-NEXT: [[BO:%.*]] = udiv i8 [[X:%.*]], 42
; CHECK-NEXT: [[NOTX:%.*]] = xor i8 [[X]], -1
; CHECK-NEXT: [[R:%.*]] = mul i8 [[BO]], [[NOTX]]
; CHECK-NEXT: ret i8 [[R]]
;
%bo = udiv i8 %x, 42
%notx = xor i8 -1, %x
%r = mul i8 %notx, %bo
ret i8 %r
}
define <2 x i8> @not_vec(<2 x i8> %x) {
; CHECK-LABEL: @not_vec(
; CHECK-NEXT: [[BO:%.*]] = udiv <2 x i8> [[X:%.*]], <i8 42, i8 -42>
; CHECK-NEXT: [[NOTX:%.*]] = xor <2 x i8> [[X]], <i8 -1, i8 -1>
; CHECK-NEXT: [[R:%.*]] = mul <2 x i8> [[BO]], [[NOTX]]
; CHECK-NEXT: ret <2 x i8> [[R]]
;
%bo = udiv <2 x i8> %x, <i8 42, i8 -42>
%notx = xor <2 x i8> <i8 -1, i8 -1>, %x
%r = mul <2 x i8> %notx, %bo
ret <2 x i8> %r
}
define <2 x i8> @not_vec_undef(<2 x i8> %x) {
; CHECK-LABEL: @not_vec_undef(
; CHECK-NEXT: [[BO:%.*]] = udiv <2 x i8> [[X:%.*]], <i8 42, i8 -42>
; CHECK-NEXT: [[NOTX:%.*]] = xor <2 x i8> [[X]], <i8 -1, i8 undef>
; CHECK-NEXT: [[R:%.*]] = mul <2 x i8> [[BO]], [[NOTX]]
; CHECK-NEXT: ret <2 x i8> [[R]]
;
%bo = udiv <2 x i8> %x, <i8 42, i8 -42>
%notx = xor <2 x i8> <i8 -1, i8 undef>, %x
%r = mul <2 x i8> %notx, %bo
ret <2 x i8> %r
}
; 'Fneg' is considered less complex than a normal binop, so the fmul should have the binop as the first operand.
; Extra uses are required to ensure that the fneg is not canonicalized after the fmul.
declare void @use(float)
declare void @use_vec(<2 x float>)
define float @fneg(float %x) {
; CHECK-LABEL: @fneg(
; CHECK-NEXT: [[BO:%.*]] = fdiv float [[X:%.*]], 4.200000e+01
; CHECK-NEXT: [[FNEGX:%.*]] = fneg float [[X]]
; CHECK-NEXT: [[R:%.*]] = fmul float [[BO]], [[FNEGX]]
; CHECK-NEXT: call void @use(float [[FNEGX]])
; CHECK-NEXT: ret float [[R]]
;
%bo = fdiv float %x, 42.0
%fnegx = fsub float -0.0, %x
%r = fmul float %fnegx, %bo
call void @use(float %fnegx)
ret float %r
}
define float @unary_fneg(float %x) {
; CHECK-LABEL: @unary_fneg(
; CHECK-NEXT: [[BO:%.*]] = fdiv float [[X:%.*]], 4.200000e+01
; CHECK-NEXT: [[FNEGX:%.*]] = fneg float [[X]]
; CHECK-NEXT: [[R:%.*]] = fmul float [[BO]], [[FNEGX]]
; CHECK-NEXT: call void @use(float [[FNEGX]])
; CHECK-NEXT: ret float [[R]]
;
%bo = fdiv float %x, 42.0
%fnegx = fneg float %x
%r = fmul float %fnegx, %bo
call void @use(float %fnegx)
ret float %r
}
define <2 x float> @fneg_vec(<2 x float> %x) {
; CHECK-LABEL: @fneg_vec(
; CHECK-NEXT: [[BO:%.*]] = fdiv <2 x float> [[X:%.*]], <float 4.200000e+01, float -4.200000e+01>
; CHECK-NEXT: [[FNEGX:%.*]] = fneg <2 x float> [[X]]
; CHECK-NEXT: [[R:%.*]] = fmul <2 x float> [[BO]], [[FNEGX]]
; CHECK-NEXT: call void @use_vec(<2 x float> [[FNEGX]])
; CHECK-NEXT: ret <2 x float> [[R]]
;
%bo = fdiv <2 x float> %x, <float 42.0, float -42.0>
%fnegx = fsub <2 x float> <float -0.0, float -0.0>, %x
%r = fmul <2 x float> %fnegx, %bo
call void @use_vec(<2 x float> %fnegx)
ret <2 x float> %r
}
define <2 x float> @fneg_vec_undef(<2 x float> %x) {
; CHECK-LABEL: @fneg_vec_undef(
; CHECK-NEXT: [[BO:%.*]] = fdiv <2 x float> [[X:%.*]], <float 4.200000e+01, float -4.200000e+01>
; CHECK-NEXT: [[FNEGX:%.*]] = fneg <2 x float> [[X]]
; CHECK-NEXT: [[R:%.*]] = fmul <2 x float> [[BO]], [[FNEGX]]
; CHECK-NEXT: call void @use_vec(<2 x float> [[FNEGX]])
; CHECK-NEXT: ret <2 x float> [[R]]
;
%bo = fdiv <2 x float> %x, <float 42.0, float -42.0>
%fnegx = fsub <2 x float> <float -0.0, float undef>, %x
%r = fmul <2 x float> %fnegx, %bo
call void @use_vec(<2 x float> %fnegx)
ret <2 x float> %r
}
define <2 x float> @unary_fneg_vec(<2 x float> %x) {
; CHECK-LABEL: @unary_fneg_vec(
; CHECK-NEXT: [[BO:%.*]] = fdiv <2 x float> [[X:%.*]], <float 4.200000e+01, float -4.200000e+01>
; CHECK-NEXT: [[FNEGX:%.*]] = fneg <2 x float> [[X]]
; CHECK-NEXT: [[R:%.*]] = fmul <2 x float> [[BO]], [[FNEGX]]
; CHECK-NEXT: call void @use_vec(<2 x float> [[FNEGX]])
; CHECK-NEXT: ret <2 x float> [[R]]
;
%bo = fdiv <2 x float> %x, <float 42.0, float -42.0>
%fnegx = fneg <2 x float> %x
%r = fmul <2 x float> %fnegx, %bo
call void @use_vec(<2 x float> %fnegx)
ret <2 x float> %r
}
|