[llvm] [InstCombine] Simplify select using KnownBits of condition (PR #95923)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 27 19:34:49 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);
----------------
goldsteinn wrote:
SInce you are essentially only going to being able to do `computeKnownBitsFromCond` up to a depth of two, can you get away with changing your `computeKnownBits` calls to use `MaxAnalysisRecursionDepth - 2`? Or does not having the additional bits matter?
https://github.com/llvm/llvm-project/pull/95923
More information about the llvm-commits
mailing list