[llvm] [InstCombine] Simplify select using KnownBits of condition (PR #95923)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 27 23:52:27 PDT 2024
================
@@ -3520,6 +3520,33 @@ static bool matchFMulByZeroIfResultEqZero(InstCombinerImpl &IC, Value *Cmp0,
return false;
}
+/// Check whether the KnownBits of a select arm may be affected by the
+/// select condition.
+static bool hasAffectedValue(Value *V, SmallPtrSetImpl<Value *> &Affected,
+ unsigned Depth) {
+ if (Depth == MaxAnalysisRecursionDepth)
+ return false;
+
+ // Ignore the case where the select arm itself is affected. These cases
+ // are handled more efficiently by other optimizations.
+ if (Affected.contains(V) && Depth != 0)
+ return true;
+
+ if (auto *I = dyn_cast<Instruction>(V)) {
+ if (isa<PHINode>(I)) {
+ if (Depth == MaxAnalysisRecursionDepth - 1)
+ return false;
+ Depth = MaxAnalysisRecursionDepth - 2;
+ }
+ return any_of(I->operands(), [&](Value *Op) {
+ return Op->getType()->isIntOrIntVectorTy() &&
+ hasAffectedValue(Op, Affected, Depth + 1);
----------------
nikic wrote:
Why do you say that computeKnownBitsFromCond() will only work up to a depth of two? Or do you mean in the phi case? (The phi case is going to pass MaxAnalysisRecursionDepth - 1 as the new depth.)
https://github.com/llvm/llvm-project/pull/95923
More information about the llvm-commits
mailing list