[llvm] [InstCombine] Improve select simplification based on known bits (PR #97289)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 7 22:07:49 PDT 2024


================
@@ -4052,22 +4052,36 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
     });
     SimplifyQuery Q = SQ.getWithInstruction(&SI).getWithCondContext(CC);
     if (!CC.AffectedValues.empty()) {
-      if (!isa<Constant>(TrueVal) &&
-          hasAffectedValue(TrueVal, CC.AffectedValues, /*Depth=*/0)) {
-        KnownBits Known = llvm::computeKnownBits(TrueVal, /*Depth=*/0, Q);
-        if (Known.isConstant())
-          return replaceOperand(SI, 1,
-                                ConstantInt::get(SelType, Known.getConstant()));
-      }
+      std::optional<bool> NotUndef;
+      auto SimplifyOp = [&](unsigned OpNum) -> Instruction * {
+        Value *V = SI.getOperand(OpNum);
+        if (isa<Constant>(V) ||
+            !hasAffectedValue(V, CC.AffectedValues, /*Depth=*/0))
+          return nullptr;
+
+        if (!NotUndef)
+          NotUndef = isGuaranteedNotToBeUndef(CondVal);
----------------
goldsteinn wrote:

Hmm? Aren't we going to end up skipping the `noundef` check on false arm if true arm makes it this far?

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


More information about the llvm-commits mailing list