[llvm] [SCCP] Support constant structure in PhiNode (PR #163713)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 17 07:01:50 PDT 2025


================
@@ -2125,6 +2143,21 @@ void SCCPInstVisitor::handleCallResult(CallBase &CB) {
   }
 }
 
+bool SCCPInstVisitor::isInstUnderDefined(Instruction &Inst) {
+  // For structure Type, we handle each member seperately.
+  // A structure object won't be considered as overDefined when
+  // there is at least one member can become constant.
+  if (StructType *STy = dyn_cast<StructType>(Inst.getType())) {
+    for (unsigned i = 0, e = STy->getNumElements(); i < e; ++i) {
+      if (!getStructValueState(&Inst, i).isOverdefined())
+        return false;
+    }
+    return true;
----------------
nikic wrote:

Not really sure how this is related -- I was just suggesting to write the same loop you currently have in a different way. But looking again, given that this is a counter loop, the result would probably not really be better, so it's fine to just leave it as-is.

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


More information about the llvm-commits mailing list