[llvm] [InstCombine] Simplify select using KnownBits of condition (PR #95923)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 27 03:55:41 PDT 2024
================
@@ -4018,5 +4018,30 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
if (CondVal->getType() == SI.getType() && isKnownInversion(FalseVal, TrueVal))
return BinaryOperator::CreateXor(CondVal, FalseVal);
+ if (SelType->isIntOrIntVectorTy()) {
+ // Try to simplify select arms based on KnownBits implied by the condition.
+ CondContext CC(CondVal);
+ findValuesAffectedByCondition(CondVal, /*IsAssume=*/false, [&](Value *V) {
+ CC.AffectedValues.insert(V);
+ });
----------------
nikic wrote:
> I mean do the full transform in a single shot as opposed to going through the work list twice.
Do you mean the case where it's possible to simplify *both* select operands? If so, this should be very rare, and as such not worth optimizing.
https://github.com/llvm/llvm-project/pull/95923
More information about the llvm-commits
mailing list