Zvi Rackover | 38ba75c | 2017-03-31 07:46:02 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | ; RUN: opt < %s -instsimplify -S | FileCheck %s |
| 3 | |
Zvi Rackover | e479980 | 2017-04-02 10:42:21 +0000 | [diff] [blame] | 4 | define <4 x i32> @const_folding(<4 x i32> %x) { |
| 5 | ; CHECK-LABEL: @const_folding( |
Zvi Rackover | 8f46065 | 2017-04-03 22:05:30 +0000 | [diff] [blame] | 6 | ; CHECK-NEXT: ret <4 x i32> zeroinitializer |
Zvi Rackover | e479980 | 2017-04-02 10:42:21 +0000 | [diff] [blame] | 7 | ; |
| 8 | %shuf = shufflevector <4 x i32> %x, <4 x i32> zeroinitializer, <4 x i32> <i32 5, i32 4, i32 5, i32 4> |
| 9 | ret <4 x i32> %shuf |
| 10 | } |
| 11 | |
Zvi Rackover | 8f46065 | 2017-04-03 22:05:30 +0000 | [diff] [blame] | 12 | define <4 x i32> @const_folding1(<4 x i32> %x) { |
| 13 | ; CHECK-LABEL: @const_folding1( |
| 14 | ; CHECK-NEXT: ret <4 x i32> <i32 5, i32 5, i32 5, i32 5> |
| 15 | ; |
| 16 | %shuf = shufflevector <4 x i32> <i32 5, i32 4, i32 5, i32 4>, <4 x i32> %x, <4 x i32> zeroinitializer |
| 17 | ret <4 x i32> %shuf |
| 18 | } |
| 19 | |
| 20 | define <4 x i32> @const_folding_negative(<3 x i32> %x) { |
| 21 | ; CHECK-LABEL: @const_folding_negative( |
| 22 | ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <3 x i32> [[X:%.*]], <3 x i32> zeroinitializer, <4 x i32> <i32 2, i32 4, i32 5, i32 4> |
| 23 | ; CHECK-NEXT: ret <4 x i32> [[SHUF]] |
| 24 | ; |
| 25 | %shuf = shufflevector <3 x i32> %x, <3 x i32> zeroinitializer, <4 x i32> <i32 2, i32 4, i32 5, i32 4> |
| 26 | ret <4 x i32> %shuf |
| 27 | } |
| 28 | |
Zvi Rackover | 38ba75c | 2017-03-31 07:46:02 +0000 | [diff] [blame] | 29 | define <4 x i32> @splat_operand(<4 x i32> %x) { |
| 30 | ; CHECK-LABEL: @splat_operand( |
| 31 | ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer |
Zvi Rackover | 30efd24d | 2017-04-11 21:37:02 +0000 | [diff] [blame] | 32 | ; CHECK-NEXT: ret <4 x i32> [[SPLAT]] |
Zvi Rackover | 38ba75c | 2017-03-31 07:46:02 +0000 | [diff] [blame] | 33 | ; |
| 34 | %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer |
| 35 | %shuf = shufflevector <4 x i32> %splat, <4 x i32> undef, <4 x i32> <i32 0, i32 3, i32 2, i32 1> |
| 36 | ret <4 x i32> %shuf |
| 37 | } |
| 38 | |
Zvi Rackover | 30efd24d | 2017-04-11 21:37:02 +0000 | [diff] [blame] | 39 | define <4 x i32> @splat_operand1(<4 x i32> %x, <4 x i32> %y) { |
| 40 | ; CHECK-LABEL: @splat_operand1( |
| 41 | ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> [[Y:%.*]], <4 x i32> zeroinitializer |
| 42 | ; CHECK-NEXT: ret <4 x i32> [[SPLAT]] |
| 43 | ; |
| 44 | %splat = shufflevector <4 x i32> %x, <4 x i32> %y, <4 x i32> zeroinitializer |
| 45 | %shuf = shufflevector <4 x i32> %splat, <4 x i32> undef, <4 x i32> <i32 0, i32 3, i32 2, i32 1> |
| 46 | ret <4 x i32> %shuf |
| 47 | } |
| 48 | |
| 49 | define <4 x i32> @splat_operand2(<4 x i32> %x, <4 x i32> %y) { |
| 50 | ; CHECK-LABEL: @splat_operand2( |
| 51 | ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer |
| 52 | ; CHECK-NEXT: ret <4 x i32> [[SPLAT]] |
| 53 | ; |
| 54 | %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer |
| 55 | %shuf = shufflevector <4 x i32> %splat, <4 x i32> %y, <4 x i32> <i32 0, i32 3, i32 2, i32 1> |
| 56 | ret <4 x i32> %shuf |
| 57 | } |
| 58 | |
| 59 | define <4 x i32> @splat_operand3(<4 x i32> %x) { |
| 60 | ; CHECK-LABEL: @splat_operand3( |
| 61 | ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer |
| 62 | ; CHECK-NEXT: ret <4 x i32> [[SPLAT]] |
| 63 | ; |
| 64 | %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer |
| 65 | %shuf = shufflevector <4 x i32> zeroinitializer, <4 x i32> %splat, <4 x i32> <i32 7, i32 6, i32 5, i32 5> |
| 66 | ret <4 x i32> %shuf |
| 67 | } |
| 68 | |
| 69 | define <8 x i32> @splat_operand_negative(<4 x i32> %x) { |
| 70 | ; CHECK-LABEL: @splat_operand_negative( |
| 71 | ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer |
| 72 | ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[SPLAT]], <4 x i32> undef, <8 x i32> <i32 0, i32 3, i32 2, i32 1, i32 undef, i32 undef, i32 undef, i32 undef> |
| 73 | ; CHECK-NEXT: ret <8 x i32> [[SHUF]] |
| 74 | ; |
| 75 | %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer |
| 76 | %shuf = shufflevector <4 x i32> %splat, <4 x i32> undef, <8 x i32> <i32 0, i32 3, i32 2, i32 1, i32 undef, i32 undef, i32 undef, i32 undef> |
| 77 | ret <8 x i32> %shuf |
| 78 | } |
| 79 | |
| 80 | define <4 x i32> @splat_operand_negative2(<4 x i32> %x, <4 x i32> %y) { |
| 81 | ; CHECK-LABEL: @splat_operand_negative2( |
| 82 | ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer |
| 83 | ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[SPLAT]], <4 x i32> [[Y:%.*]], <4 x i32> <i32 0, i32 3, i32 4, i32 1> |
| 84 | ; CHECK-NEXT: ret <4 x i32> [[SHUF]] |
| 85 | ; |
| 86 | %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer |
| 87 | %shuf = shufflevector <4 x i32> %splat, <4 x i32> %y, <4 x i32> <i32 0, i32 3, i32 4, i32 1> |
| 88 | ret <4 x i32> %shuf |
| 89 | } |
| 90 | |
| 91 | define <4 x i32> @splat_operand_negative3(<4 x i32> %x, <4 x i32> %y) { |
| 92 | ; CHECK-LABEL: @splat_operand_negative3( |
| 93 | ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer |
| 94 | ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[Y:%.*]], <4 x i32> [[SPLAT]], <4 x i32> <i32 0, i32 3, i32 4, i32 1> |
| 95 | ; CHECK-NEXT: ret <4 x i32> [[SHUF]] |
| 96 | ; |
| 97 | %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer |
| 98 | %shuf = shufflevector <4 x i32> %y, <4 x i32> %splat, <4 x i32> <i32 0, i32 3, i32 4, i32 1> |
| 99 | ret <4 x i32> %shuf |
| 100 | } |
| 101 | |
| 102 | define <4 x i32> @splat_operand_negative4(<4 x i32> %x) { |
| 103 | ; CHECK-LABEL: @splat_operand_negative4( |
| 104 | ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> <i32 2, i32 undef, i32 2, i32 undef> |
| 105 | ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[SPLAT]], <4 x i32> undef, <4 x i32> <i32 0, i32 2, i32 undef, i32 undef> |
| 106 | ; CHECK-NEXT: ret <4 x i32> [[SHUF]] |
| 107 | ; |
| 108 | %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> <i32 2, i32 undef, i32 2, i32 undef> |
| 109 | %shuf = shufflevector <4 x i32> %splat, <4 x i32> undef, <4 x i32> <i32 0, i32 2, i32 undef, i32 undef> |
| 110 | ret <4 x i32> %shuf |
| 111 | } |
| 112 | |
Zvi Rackover | 38ba75c | 2017-03-31 07:46:02 +0000 | [diff] [blame] | 113 | define <4 x i32> @undef_mask(<4 x i32> %x) { |
| 114 | ; CHECK-LABEL: @undef_mask( |
Zvi Rackover | 8f46065 | 2017-04-03 22:05:30 +0000 | [diff] [blame] | 115 | ; CHECK-NEXT: ret <4 x i32> undef |
Zvi Rackover | 38ba75c | 2017-03-31 07:46:02 +0000 | [diff] [blame] | 116 | ; |
| 117 | %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> undef |
| 118 | ret <4 x i32> %shuf |
| 119 | } |
| 120 | |
Zvi Rackover | 4086e13 | 2017-04-30 06:06:26 +0000 | [diff] [blame^] | 121 | define <4 x i32> @undef_mask_1(<4 x i32> %x, <4 x i32> %y) { |
| 122 | ; CHECK-LABEL: @undef_mask_1( |
| 123 | ; CHECK-NEXT: ret <4 x i32> undef |
| 124 | ; |
| 125 | %shuf = shufflevector <4 x i32> %x, <4 x i32> %y, <4 x i32> undef |
| 126 | ret <4 x i32> %shuf |
| 127 | } |
| 128 | |
Zvi Rackover | 38ba75c | 2017-03-31 07:46:02 +0000 | [diff] [blame] | 129 | define <4 x i32> @identity_mask_0(<4 x i32> %x) { |
| 130 | ; CHECK-LABEL: @identity_mask_0( |
Sanjay Patel | a3c297d | 2017-04-19 16:48:22 +0000 | [diff] [blame] | 131 | ; CHECK-NEXT: ret <4 x i32> [[X:%.*]] |
Zvi Rackover | 38ba75c | 2017-03-31 07:46:02 +0000 | [diff] [blame] | 132 | ; |
| 133 | %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3> |
| 134 | ret <4 x i32> %shuf |
| 135 | } |
| 136 | |
| 137 | define <4 x i32> @identity_mask_1(<4 x i32> %x) { |
| 138 | ; CHECK-LABEL: @identity_mask_1( |
Sanjay Patel | a3c297d | 2017-04-19 16:48:22 +0000 | [diff] [blame] | 139 | ; CHECK-NEXT: ret <4 x i32> [[X:%.*]] |
Zvi Rackover | 38ba75c | 2017-03-31 07:46:02 +0000 | [diff] [blame] | 140 | ; |
| 141 | %shuf = shufflevector <4 x i32> undef, <4 x i32> %x, <4 x i32> <i32 4, i32 5, i32 6, i32 7> |
| 142 | ret <4 x i32> %shuf |
| 143 | } |
| 144 | |
| 145 | define <4 x i32> @pseudo_identity_mask(<4 x i32> %x) { |
| 146 | ; CHECK-LABEL: @pseudo_identity_mask( |
Sanjay Patel | a3c297d | 2017-04-19 16:48:22 +0000 | [diff] [blame] | 147 | ; CHECK-NEXT: ret <4 x i32> [[X:%.*]] |
Zvi Rackover | 38ba75c | 2017-03-31 07:46:02 +0000 | [diff] [blame] | 148 | ; |
| 149 | %shuf = shufflevector <4 x i32> %x, <4 x i32> %x, <4 x i32> <i32 0, i32 1, i32 2, i32 7> |
| 150 | ret <4 x i32> %shuf |
| 151 | } |
| 152 | |
Sanjay Patel | a3c297d | 2017-04-19 16:48:22 +0000 | [diff] [blame] | 153 | define <4 x i32> @not_identity_mask(<4 x i32> %x) { |
| 154 | ; CHECK-LABEL: @not_identity_mask( |
| 155 | ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> [[X]], <4 x i32> <i32 0, i32 1, i32 2, i32 6> |
| 156 | ; CHECK-NEXT: ret <4 x i32> [[SHUF]] |
| 157 | ; |
| 158 | %shuf = shufflevector <4 x i32> %x, <4 x i32> %x, <4 x i32> <i32 0, i32 1, i32 2, i32 6> |
| 159 | ret <4 x i32> %shuf |
| 160 | } |
| 161 | |
| 162 | ; TODO: Should we simplify if the mask has an undef element? |
| 163 | |
| 164 | define <4 x i32> @possible_identity_mask(<4 x i32> %x) { |
| 165 | ; CHECK-LABEL: @possible_identity_mask( |
| 166 | ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef> |
| 167 | ; CHECK-NEXT: ret <4 x i32> [[SHUF]] |
| 168 | ; |
| 169 | %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef> |
| 170 | ret <4 x i32> %shuf |
| 171 | } |
| 172 | |
Zvi Rackover | 38ba75c | 2017-03-31 07:46:02 +0000 | [diff] [blame] | 173 | define <4 x i32> @const_operand(<4 x i32> %x) { |
| 174 | ; CHECK-LABEL: @const_operand( |
Zvi Rackover | 8f46065 | 2017-04-03 22:05:30 +0000 | [diff] [blame] | 175 | ; CHECK-NEXT: ret <4 x i32> <i32 42, i32 45, i32 44, i32 43> |
Zvi Rackover | 38ba75c | 2017-03-31 07:46:02 +0000 | [diff] [blame] | 176 | ; |
| 177 | %shuf = shufflevector <4 x i32> <i32 42, i32 43, i32 44, i32 45>, <4 x i32> %x, <4 x i32> <i32 0, i32 3, i32 2, i32 1> |
| 178 | ret <4 x i32> %shuf |
| 179 | } |
| 180 | |
| 181 | define <4 x i32> @merge(<4 x i32> %x) { |
| 182 | ; CHECK-LABEL: @merge( |
Sanjay Patel | a3c297d | 2017-04-19 16:48:22 +0000 | [diff] [blame] | 183 | ; CHECK-NEXT: ret <4 x i32> [[X:%.*]] |
Zvi Rackover | 38ba75c | 2017-03-31 07:46:02 +0000 | [diff] [blame] | 184 | ; |
| 185 | %lower = shufflevector <4 x i32> %x, <4 x i32> undef, <2 x i32> <i32 1, i32 0> |
| 186 | %upper = shufflevector <4 x i32> %x, <4 x i32> undef, <2 x i32> <i32 2, i32 3> |
| 187 | %merged = shufflevector <2 x i32> %upper, <2 x i32> %lower, <4 x i32> <i32 3, i32 2, i32 0, i32 1> |
| 188 | ret <4 x i32> %merged |
| 189 | } |
Sanjay Patel | f0cb5a8 | 2017-04-11 20:54:57 +0000 | [diff] [blame] | 190 | |
Sanjay Patel | a3c297d | 2017-04-19 16:48:22 +0000 | [diff] [blame] | 191 | ; This crosses lanes from the source op. |
| 192 | |
| 193 | define <4 x i32> @not_merge(<4 x i32> %x) { |
| 194 | ; CHECK-LABEL: @not_merge( |
| 195 | ; CHECK-NEXT: [[L:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <2 x i32> <i32 0, i32 1> |
| 196 | ; CHECK-NEXT: [[U:%.*]] = shufflevector <4 x i32> [[X]], <4 x i32> undef, <2 x i32> <i32 2, i32 3> |
| 197 | ; CHECK-NEXT: [[MERGED:%.*]] = shufflevector <2 x i32> [[U]], <2 x i32> [[L]], <4 x i32> <i32 3, i32 2, i32 0, i32 1> |
| 198 | ; CHECK-NEXT: ret <4 x i32> [[MERGED]] |
| 199 | ; |
| 200 | %l = shufflevector <4 x i32> %x, <4 x i32> undef, <2 x i32> <i32 0, i32 1> |
| 201 | %u = shufflevector <4 x i32> %x, <4 x i32> undef, <2 x i32> <i32 2, i32 3> |
| 202 | %merged = shufflevector <2 x i32> %u, <2 x i32> %l, <4 x i32> <i32 3, i32 2, i32 0, i32 1> |
| 203 | ret <4 x i32> %merged |
| 204 | } |
| 205 | |
Sanjay Patel | f0cb5a8 | 2017-04-11 20:54:57 +0000 | [diff] [blame] | 206 | define <8 x double> @extract_and_concat(<8 x double> %x) { |
| 207 | ; CHECK-LABEL: @extract_and_concat( |
Sanjay Patel | a3c297d | 2017-04-19 16:48:22 +0000 | [diff] [blame] | 208 | ; CHECK-NEXT: ret <8 x double> [[X:%.*]] |
Sanjay Patel | f0cb5a8 | 2017-04-11 20:54:57 +0000 | [diff] [blame] | 209 | ; |
| 210 | %s1 = shufflevector <8 x double> %x, <8 x double> undef, <2 x i32> <i32 0, i32 1> |
| 211 | %s2 = shufflevector <8 x double> %x, <8 x double> undef, <2 x i32> <i32 2, i32 3> |
| 212 | %s3 = shufflevector <8 x double> %x, <8 x double> undef, <2 x i32> <i32 4, i32 5> |
| 213 | %s4 = shufflevector <8 x double> %x, <8 x double> undef, <2 x i32> <i32 6, i32 7> |
| 214 | %s5 = shufflevector <2 x double> %s1, <2 x double> %s2, <4 x i32> <i32 0, i32 1, i32 2, i32 3> |
| 215 | %s6 = shufflevector <2 x double> %s3, <2 x double> %s4, <4 x i32> <i32 0, i32 1, i32 2, i32 3> |
| 216 | %s7 = shufflevector <4 x double> %s5, <4 x double> %s6, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7> |
| 217 | ret <8 x double> %s7 |
| 218 | } |
| 219 | |
| 220 | ; This case has intermediate lane crossings. |
| 221 | |
| 222 | define <8 x i64> @PR30630(<8 x i64> %x) { |
| 223 | ; CHECK-LABEL: @PR30630( |
Sanjay Patel | a3c297d | 2017-04-19 16:48:22 +0000 | [diff] [blame] | 224 | ; CHECK-NEXT: ret <8 x i64> [[X:%.*]] |
Sanjay Patel | f0cb5a8 | 2017-04-11 20:54:57 +0000 | [diff] [blame] | 225 | ; |
| 226 | %s1 = shufflevector <8 x i64> %x, <8 x i64> undef, <2 x i32> <i32 0, i32 4> |
| 227 | %s2 = shufflevector <8 x i64> %x, <8 x i64> undef, <2 x i32> <i32 1, i32 5> |
| 228 | %s3 = shufflevector <8 x i64> %x, <8 x i64> undef, <2 x i32> <i32 2, i32 6> |
| 229 | %s4 = shufflevector <8 x i64> %x, <8 x i64> undef, <2 x i32> <i32 3, i32 7> |
| 230 | %s5 = shufflevector <2 x i64> %s1, <2 x i64> %s2, <4 x i32> <i32 0, i32 1, i32 2, i32 3> |
| 231 | %s6 = shufflevector <2 x i64> %s3, <2 x i64> %s4, <4 x i32> <i32 0, i32 1, i32 2, i32 3> |
| 232 | %s7 = shufflevector <4 x i64> %s5, <4 x i64> %s6, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 1, i32 3, i32 5, i32 7> |
| 233 | ret <8 x i64> %s7 |
| 234 | } |
| 235 | |