[llvm] [InstCombine] Simplify select using KnownBits of condition (PR #95923)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 13:58:24 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);
+    });
----------------
goldsteinn wrote:

> As mentioned in the PR description, most of the overhead comes from simply adding a member to SimplifyQuery rather than anything happening in InstCombine. These are the numbers just for adding a dummy member: https://llvm-compile-time-tracker.com/compare.php?from=3ca17443ef4af21bdb1f3b4fbcfff672cbc6176c&to=e7a64d837a061d6afeac9c0f06c4827998d43561&stat=instructions:u
> 
> As such, I don't think we'll get any substantial improvement out of changing how exactly the KnownBits calculation is done.
> 
I see, although a bit more ugly, what about adding an additional optional argument to `computeKnownBits`/`computeKnownBitsFromContext`?

https://github.com/llvm/llvm-project/pull/95923


More information about the llvm-commits mailing list