[llvm] ValueTracking: Extract isKnownIntegral out of AMDGPU (PR #177912)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 26 10:55:17 PST 2026


================
@@ -6229,6 +6229,73 @@ bool llvm::canIgnoreSignBitOfNaN(const Use &U) {
   }
 }
 
+bool llvm::isKnownIntegral(const Value *V, const SimplifyQuery &SQ,
+                           FastMathFlags FMF) {
+  if (isa<PoisonValue>(V))
+    return true;
+  if (isa<UndefValue>(V))
+    return false;
+
+  if (const ConstantFP *CF = dyn_cast<ConstantFP>(V))
+    return CF->getValueAPF().isInteger();
+
+  auto *VFVTy = dyn_cast<FixedVectorType>(V->getType());
+  const Constant *CV = dyn_cast<Constant>(V);
+  if (VFVTy && CV) {
+    unsigned NumElts = VFVTy->getNumElements();
+    for (unsigned i = 0; i != NumElts; ++i) {
+      Constant *Elt = CV->getAggregateElement(i);
+      if (!Elt)
+        return false;
+      if (isa<PoisonValue>(Elt))
+        continue;
+
+      const ConstantFP *CFP = dyn_cast<ConstantFP>(Elt);
+      if (!CFP || !CFP->getValue().isInteger())
+        return false;
+    }
+
+    return true;
+  }
----------------
arsenm wrote:

I'll do it as a follow up 

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


More information about the llvm-commits mailing list