Lines Matching full:select
53 /// Replace a select operand based on an equality comparison with the identity
58 // The select condition must be an equality compare with a constant operand.
75 // A select operand must be a binop.
107 // S = { select (cmp eq X, C), BO, ? } or { select (cmp ne X, C), ?, BO }
109 // S = { select (cmp eq X, C), Y, ? } or { select (cmp ne X, C), ?, Y }
114 /// select (icmp eq (and X, C1)), TC, FC
129 // If this is a vector select, we need a vector compare.
160 // replace the select. This would require more instructions than we started
166 // If the select constants differ by exactly one bit and that's the same
167 // bit that is masked and checked by the select condition, the select can
196 // Make sure one of the select arms is a power-of-2.
208 // If we would need to create an 'and' + 'shift' + 'xor' to replace a 'select'
218 // If types don't match, we can still convert the select by introducing a zext
240 /// %D = select %cond, %C, %A
242 /// %C = select %cond, %B, 0
245 /// Assuming that the specified instruction is an operand to the select, return
247 /// equal the other incoming value of the select.
270 /// We have (select c, TI, FI), and we know that TI and FI have the same opcode.
291 // The select condition may be a vector. We may only change the operand
301 // worse codegen by promoting the select ahead of size-altering casts
311 // TODO: The one-use restrictions for a scalar select could be eased if
312 // the fold of a select in visitLoadInst() was enhanced to match a pattern
317 // Fold this by inserting a select from the input values.
370 // select.
384 // pulled after the select. This is the same transform as below for binops,
398 // select c, (ldexp v, e0), (ldexp v, e1) -> ldexp v, (select c, e0, e1)
399 // select c, (ldexp v0, e), (ldexp v1, e) -> ldexp (select c, v0, v1), e
401 // select c, (ldexp v0, e0), (ldexp v1, e1) ->
402 // ldexp (select c, v0, v1), (select c, e0, e1)
426 // pulled after the select.
459 // If the select condition is a vector, the operands of the original select's
466 // If we are sinking div/rem after a select, we may need to freeze the
508 /// Try to fold the select into one of the operands to allow further
531 // TODO: We probably ought to revisit cases where the select and FP
540 // Avoid creating select between 2 constants unless it's selecting
579 /// (select (icmp eq (and X, Y), 0), (and (lshr X, Z), 1), 1)
585 /// instructions, but we got rid of select.
630 /// (select (icmp eq (and X, C1), 0), 0, (shl [nsw/nuw] X, C2));
668 /// (select (icmp sgt x, C), lshr (X, Y), ashr (X, Y)); iff C s>= -1
669 /// (select (icmp slt x, C), ashr (X, Y), lshr (X, Y)); iff C s>= 0
708 /// (select (icmp eq (and X, C1), 0), Y, (BinOp Y, C2))
725 /// 2. The select operands are reversed
730 // Only handle integer compares. Also, if this is a vector select, we need a
817 /// select-of-constants form.
848 // select (x == 0), 0, x * y --> freeze(y) * x
849 // select (y == 0), 0, x * y --> freeze(x) * y
850 // select (x == 0), undef, x * y --> freeze(y) * x
851 // select (x == undef), 0, x * y --> freeze(y) * x
867 // the select expression should be already simplified.
991 // Canonicalize -1 (saturated result) to true value of the select.
1040 /// Try to match patterns with select and subtract as absolute difference.
1053 // Normalize "A - B" as the true value of the select.
1122 /// Attempt to fold a cttz/ctlz followed by a icmp plus select into a single
1129 /// %2 = select i1 %1, i32 %0, i32 32
1140 // Check if the select condition compares a value for equality.
1184 // zext/trunc) have one use (ending at the select), the cttz/ctlz result will
1270 /// If we have a select with an equality comparison, then we know the value in
1271 /// one of the arms of the select. See if substituting this value into an arm
1275 /// (nsw, etc) if we simplified to a binop because the select may be guarding
1282 /// %sel = select i1 %cmp, i32 -2147483648, i32 %add
1291 // Canonicalize the pattern to ICMP_EQ by swapping the select operands.
1358 // We have an 'EQ' comparison, so the select's false value will propagate.
1381 // %old_replacement = select i1 %old_cmp1, i32 %target_low, i32 %target_high
1384 // %r = select i1 %old_cmp0, i32 %x, i32 %old_replacement
1388 // %new_clamped_low = select i1 %new_cmp1, i32 %target_low, i32 %x
1389 // %r = select i1 %new_cmp2, i32 %target_high, i32 %new_clamped_low
1399 // First match the condition of the outermost select.
1445 // the select in other hand should be one-use.
1454 // We now can finish matching the condition of the outermost select:
1556 // Create the final select. If we looked through a truncate above, we will
1565 // %r = select i1 %cmp, i32 %y, i32 C1
1568 // the result) is identical to the C1 in select. If it matches we can change
1570 // and swap the hands of select.
1591 // If the [input] type of comparison and select type are different, lets abort
1611 // Does this constant C match any of the `select` values?
1616 // If C0 *already* matches true/false value of select, we are done.
1630 // It matched! Lets insert the new comparison just before select.
1868 // not applied with any constant select arm.
1965 /// SI is a select whose condition is a PHI node (but the two may be in
1971 /// Z = select X, Y, 0
1989 // Otherwise, if the PHI and select are defined in the same block and if V is
2021 /// Turn select C, (X + Y), (X - Y) --> (X + (select C, Y, (-Y))).
2058 // select C, (add X, Y), (sub X, Z)
2228 // If we are extending from a boolean type or if we can create a select that
2229 // has the same size operands as its condition, try to narrow the select.
2239 // extension to the original type, we can narrow the select.
2247 // select Cond, (ext X), C --> ext(select Cond, X, C')
2248 // select Cond, C, (ext X) --> ext(select Cond, C', X)
2256 /// Try to transform a vector select with a constant condition vector into a
2274 // If the select condition element is true, choose from the 1st vector.
2277 // If the select condition element is false, choose from the 2nd vector.
2280 // Undef in a select condition (choose one of the operands) does not mean
2293 /// If we have a select of vectors with a scalar condition, try to convert that
2294 /// to a vector select by splatting the condition. A splat may get folded with
2295 /// other operations in IR and having all operands of a select be vector types
2308 // select (extelt V, Index), T, F --> select (splat V, Index), T, F
2315 /// Reuse bitcasted operands between a compare and select:
2316 /// select (cmp (bitcast C), (bitcast D)), (bitcast' C), (bitcast' D) -->
2317 /// bitcast (select (cmp (bitcast C), (bitcast D)), (bitcast C), (bitcast D))
2329 // The select condition is a compare instruction. If the select's true/false
2338 // select (cmp (bitcast C), (bitcast D)), (bitcast TSrc), (bitcast FSrc)
2344 // If the select true/false values are *different bitcasts* of the same source
2345 // operands, make the select operands the same as the compare operands and
2346 // cast the result. This is the canonical select form for min/max.
2349 // select (cmp (bitcast C), (bitcast D)), (bitcast' C), (bitcast' D) -->
2350 // bitcast (select (cmp A, B), A, B)
2353 // select (cmp (bitcast C), (bitcast D)), (bitcast' D), (bitcast' C) -->
2354 // bitcast (select (cmp A, B), B, A)
2362 /// Try to eliminate select instructions that test the returned flag of cmpxchg
2365 /// If a select instruction tests the returned flag of a cmpxchg instruction and
2367 /// operand, the result of the select will always be equal to its false value.
2373 /// %sel = select i1 %success, i64 %compare, i64 %val
2378 /// must have been equal to %compare. Thus, the result of the select is always
2399 // If the select has a single user, and this user is a select instruction that
2402 if (auto *Select = dyn_cast<SelectInst>(SI.user_back()))
2403 if (Select->getCondition() == SI.getCondition())
2404 if (Select->getFalseValue() == SI.getTrueValue() ||
2405 Select->getTrueValue() == SI.getFalseValue())
2408 // Ensure the select condition is the returned flag of a cmpxchg instruction.
2413 // Check the true value case: The true value of the select is the returned
2420 // Check the false value case: The false value of the select is the returned
2430 /// Try to reduce a funnel/rotate pattern that includes a compare and select
2477 // select ?, TVal, (or (shl SV0, SA0), (lshr SV1, SA1))
2478 // The false value of the select must be a funnel-shift of the true value:
2485 // Finally, see if the select is filtering out a shift-by-zero.
2492 // If this is not a rotate then the select was blocking poison from the
2516 // Match select ?, TC, FC where the constants are equal but negated.
2524 assert(TC != FC && "Expected equal select arms to simplify");
2540 // Note: FMF from the select can not be propagated to the new instructions.
2573 // select rev(C), rev(X), rev(Y) --> rev(select C, X, Y)
2578 // select rev(C), rev(X), FValSplat --> rev(select C, X, FValSplat)
2582 // select rev(C), TValSplat, rev(Y) --> rev(select C, TValSplat, Y)
2601 // A select of a "select shuffle" with a common operand can be rearranged
2602 // to select followed by "select shuffle". Because of poison, this only works
2609 // select Cond, (shuf_sel X, Y), X --> shuf_sel X, (select Cond, Y, X)
2614 // select Cond, (shuf_sel X, Y), Y --> shuf_sel (select Cond, X, Y), Y
2623 // select Cond, X, (shuf_sel X, Y) --> shuf_sel X, (select Cond, X, Y)
2628 // select Cond, Y, (shuf_sel X, Y) --> shuf_sel (select Cond, Y, X), Y
2641 // that matches select's condition (maybe inverted).
2667 // We want to replace select %cond, %a, %b with a phi that takes value %a
2700 // Try to replace this select with Phi in one of these blocks.
2735 // of the select are inverted.
2749 // %sel = select i1 %cnd, i32 %add, i32 %rem
2759 // %sel = select i1 %cnd, i32 1, i32 %rem
2776 // select (freeze(x == y)), x, y --> y
2777 // select (freeze(x != y)), x, y --> x
2778 // The freeze should be only used by this select. Otherwise, remaining uses of
2781 // a = select c, x, y ;
2823 // Canonicalize select with fcmp to fabs(). -0.0 makes this tricky. We need
2857 // Forward-propagate nnan and ninf from the fneg to the select.
2858 // If all inputs are not those values, then the select is not either.
2903 // Match select with (icmp slt (bitcast X to int), 0)
2941 // %x.roundedup = select i1 %x.lowbits.are.zero, i8 %x, i8 %x.biased.highbits
3019 /// select c2 (select c1 a b) (select c1 b a)
3021 /// select (xor c1 c2) b a
3045 /// %outer.cond = select i1 %inner.cond, i1 %alt.cond, i1 false
3046 /// %inner.sel = select i1 %inner.cond, i8 %inner.sel.t, i8 %inner.sel.f
3047 /// %outer.sel = select i1 %outer.cond, i8 %outer.sel.t, i8 %inner.sel
3049 /// %inner.sel = select i1 %cond.alternative, i8 %sel.outer.t, i8 %sel.inner.t
3050 /// %sel.outer = select i1 %cond.inner, i8 %inner.sel, i8 %sel.inner.f
3053 // We must start with a `select`.
3059 // Canonicalize inversion of the outermost `select`'s condition.
3063 // The condition of the outermost select must be an `and`/`or`.
3067 // Depending on the logical op, inner select might be in different hand.
3076 // The appropriate hand of the outermost `select` must be a select itself.
3083 // Canonicalize inversion of the innermost `select`'s condition.
3089 // An unsimplified select condition can match both LogicalAnd and LogicalOr
3090 // (select true, true, false). Since below we assume that LogicalAnd implies
3099 // Finally, match the condition that was driving the outermost `select`,
3101 // the innermost `select` (after accounting for the possible inversions
3130 // Scalar select must have simplified?
3139 // Folding select to and/or i1 isn't poison safe in general. impliesPoison
3144 // Change: A = select B, true, C --> A = or B, C
3192 // Change: A = select B, C, false --> A = and B, C
3240 // select a, false, b -> select !a, b, false
3245 // select a, b, true -> select !a, true, b
3251 // DeMorgan in select form: !a && !b --> !(a || b)
3252 // select !a, !b, false --> not (select a, true, b)
3258 // DeMorgan in select form: !a || !b --> !(a && b)
3259 // select !a, true, !b --> not (select a, b, false)
3265 // select (select a, true, b), true, b -> select a, true, b
3269 // select (select a, b, false), b, false -> select a, b, false
3279 // select (~a | c), a, b -> select a, (select c, true, b), false
3285 // select (c & b), a, b -> select b, (select ~c, true, a), false
3292 // select (a | c), a, b -> select a, true, (select ~c, b, false)
3299 // select (c & ~b), a, b -> select b, true, (select c, a, false)
3324 // select (a || b), c, false -> select a, c, false
3325 // select c, (a || b), false -> select c, a, false
3339 // select c, true, (a && b) -> select c, true, a
3340 // select (a && b), true, c -> select a, true, c
3394 // Return true if we can safely remove the select instruction for std::bit_ceil
3401 // for the CTLZ proper and select condition, each possibly with some
3405 // select instruction would select 1, which allows us to get rid of the select
3477 // %sel = select i1 %ugt, i32 %shl, i32 1
3487 // Note that the select is optimized away while the shift count is masked with
3548 // nsz must be on the select, it must be ignored on the multiply. We
3557 /// Check whether the KnownBits of a select arm may be affected by the
3558 /// select condition.
3564 // Ignore the case where the select arm itself is affected. These cases
3600 // If the type of select is not an integer type or if the condition and
3622 // Note that we don't handle a scalar select of vectors:
3623 // select i1 %c, <2 x i8> <1, 1>, <2 x i8> <0, 0>
3631 // select C, 1, 0 -> zext C to int
3635 // select C, -1, 0 -> sext C to int
3639 // select C, 0, 1 -> zext !C to int
3645 // select C, 0, -1 -> sext !C to int
3660 // Canonicalize to use ordered comparisons by swapping the select
3668 // FIXME: The FMF should propagate from the select, not the fcmp.
3694 // (select (fcmp [ou]eq x, 0.0), (fmul x, K), x => x
3695 // (select (fcmp [ou]ne x, 0.0), x, (fmul x, K) => x
3712 // TODO: Try to forward-propagate FMF from select arms to the select.
3714 // Canonicalize select of FP values where NaN and -0.0 are not valid as
3746 // Turn (select C, (op X, Y), (op X, Z)) -> (op X, (select C, Y, Z))
3759 // Fold (select C, (gep Ptr, Idx), Ptr) -> (gep Ptr, (select C, Idx, 0))
3760 // Fold (select C, Ptr, (gep Ptr, Idx)) -> (gep Ptr, (select C, 0, Idx))
3787 // See if we can fold the select into one of our operands.
3810 // - type casts are outside select patterns.
3843 // See if we can fold the select into a phi node if the condition is a select.
3859 // select(C0, select(C1, a, b), b) -> select(C0&C1, a, b)
3879 // select(C0, a, select(C1, a, b)) -> select(C0|C1, a, b)
3890 // condition. This is not valid for div/rem because the select might be
3894 // select(C, binop(select(C, X, Y), W), Z) -> select(C, binop(X, W), Z)
3913 // select(C, Z, binop(select(C, X, Y), W)) -> select(C, Z, binop(Y, W))
3944 // If we can compute the condition, there's no need for a select.
3965 if (Instruction *Select = foldSelectBinOpIdentity(SI, TLI, *this))
3966 return Select;
3983 // select(mask, mload(,,mask,0), 0) -> mload(,,mask,0)
4003 // We can remove the select by ensuring the load zeros all lanes the
4004 // select would have. We determine this by proving there is no overlap
4005 // between the load and select masks.
4036 // (select A && B, T, F) -> (select A, (select B, T, F), F)
4037 // (select A || B, T, F) -> (select A, T, (select B, T, F))
4038 // if (select B, T, F) is foldable.
4046 // Is (select B, T, F) a SPF?
4080 // select Cond, !X, X -> xor Cond, X
4088 // Try to simplify select arms based on KnownBits implied by the condition.