[llvm] [InstCombine] Lower flag check pattern to use a bitmask-shift (PR #169557)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 11 04:55:12 PST 2026


================
@@ -2410,6 +2410,64 @@ Value *InstCombinerImpl::reassociateBooleanAndOr(Value *LHS, Value *X, Value *Y,
   return nullptr;
 }
 
+static Value *combineAndOrOfImmCmpToBitExtract(Instruction &Or,
+                                               InstCombiner::BuilderTy &Builder,
+                                               const DataLayout &DL) {
+  // Currently only support scalars
+  if (Or.getType()->isVectorTy())
+    return nullptr;
+
+  ConstantComparesGatherer ConstantCompare(&Or, DL, /*OneUse=*/true);
+  // Unpack the result
+  SmallVectorImpl<ConstantInt *> &Values = ConstantCompare.Vals;
+  Value *Index = ConstantCompare.CompValue;
+
+  // TODO: Handle ConstantCompare.Extra case
+  // If expanding an existing case, only adding one extra case is still good
+  if (!Index || !isGuaranteedNotToBeUndefOrPoison(Index) ||
----------------
dtcxzyw wrote:

Is `isGuaranteedNotToBeUndefOrPoison` needed? If the index is poison, the whole expression is also poison.

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


More information about the llvm-commits mailing list