[llvm] [BDCE] Handle multi-use `select` of `and`s on demanded bits (PR #79688)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 27 03:15:13 PST 2024


================
@@ -125,6 +125,33 @@ static bool bitTrackingDCE(Function &F, DemandedBits &DB) {
       }
     }
 
+    // Simplify select of ands when the mask does not affect the demanded bits.
+    if (SelectInst *SI = dyn_cast<SelectInst>(&I)) {
+      APInt Demanded = DB.getDemandedBits(SI);
+      if (!Demanded.isAllOnes()) {
+        for (Use &U : I.operands()) {
+          auto *And = dyn_cast<BinaryOperator>(&U);
+          if (!And || !And->hasOneUse() || And->getOpcode() != Instruction::And)
----------------
dtcxzyw wrote:

Can we also handle select of `Or`s? You can leave a todo here to do later.



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


More information about the llvm-commits mailing list