[llvm] 6d702a1 - [NewGVN] Prefer poison to undef when ranking operands

Nuno Lopes via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 29 05:09:55 PST 2021


Author: Nuno Lopes
Date: 2021-12-29T12:38:14Z
New Revision: 6d702a1e6a069e22e4b7f679a408e95bcc7db66c

URL: https://github.com/llvm/llvm-project/commit/6d702a1e6a069e22e4b7f679a408e95bcc7db66c
DIFF: https://github.com/llvm/llvm-project/commit/6d702a1e6a069e22e4b7f679a408e95bcc7db66c.diff

LOG: [NewGVN] Prefer poison to undef when ranking operands
ping @alinas

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/NewGVN.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp
index 10a8742940b11..d0d6fc81e8b6c 100644
--- a/llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -4128,21 +4128,25 @@ bool NewGVN::eliminateInstructions(Function &F) {
 unsigned int NewGVN::getRank(const Value *V) const {
   // Prefer constants to undef to anything else
   // Undef is a constant, have to check it first.
+  // Prefer poison to undef as it's less defined.
   // Prefer smaller constants to constantexprs
+  // Note that the order here matters because of class inheritance
   if (isa<ConstantExpr>(V))
-    return 2;
-  if (isa<UndefValue>(V))
+    return 3;
+  if (isa<PoisonValue>(V))
     return 1;
+  if (isa<UndefValue>(V))
+    return 2;
   if (isa<Constant>(V))
     return 0;
-  else if (auto *A = dyn_cast<Argument>(V))
-    return 3 + A->getArgNo();
+  if (auto *A = dyn_cast<Argument>(V))
+    return 4 + A->getArgNo();
 
-  // Need to shift the instruction DFS by number of arguments + 3 to account for
+  // Need to shift the instruction DFS by number of arguments + 5 to account for
   // the constant and argument ranking above.
   unsigned Result = InstrToDFSNum(V);
   if (Result > 0)
-    return 4 + NumFuncArgs + Result;
+    return 5 + NumFuncArgs + Result;
   // Unreachable or something else, just return a really large number.
   return ~0;
 }


        


More information about the llvm-commits mailing list