[llvm] [GVN] Replace cmp with not instruction if inv cmp is found (PR #223171)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 04:04:35 PDT 2026


================
@@ -3445,18 +3451,29 @@ bool GVNPass::processInstruction(Instruction *I) {
     }
   }
 
-  // If the number we were assigned was a brand new VN, then we don't
-  // need to do a lookup to see if the number already exists
-  // somewhere in the domtree: it can't!
-  if (Num >= NextNum) {
-    LeaderTable.insert(Num, I, I->getParent());
-    return false;
-  }
-
   // Perform fast-path value-number based elimination of values inherited from
-  // dominators.
-  Value *Repl = findLeader(I->getParent(), Num);
+  // dominators, unless if the number we were assigned was a brand new VN, then
+  // we don't need to do a lookup to see if the number already exists somewhere
+  // in the domtree: it can't!
+  Value *Repl = Num < NextNum ? findLeader(I->getParent(), Num) : nullptr;
   if (!Repl) {
+    // substiut cmp instruction with not if possible.
----------------
dtcxzyw wrote:

substitute

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


More information about the llvm-commits mailing list