[llvm] c1b3e32 - [NFC][InstructionSimplify] Add a warning about not simplifying to not def-reachable

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 28 23:58:26 PDT 2020


Author: Roman Lebedev
Date: 2020-08-29T09:58:08+03:00
New Revision: c1b3e32118adff13bf846e0aa8b0b3b4ec04a120

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

LOG: [NFC][InstructionSimplify] Add a warning about not simplifying to not def-reachable

See
https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20200824/824235.html
and
https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20200824/824967.html

InstSimply is not allowed to perform simplifications to instructions
that are not def-reachable from the original instruction.

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/InstructionSimplify.h
    llvm/lib/Analysis/InstructionSimplify.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/InstructionSimplify.h b/llvm/include/llvm/Analysis/InstructionSimplify.h
index 7a69d20154b0..6f3d16846621 100644
--- a/llvm/include/llvm/Analysis/InstructionSimplify.h
+++ b/llvm/include/llvm/Analysis/InstructionSimplify.h
@@ -26,6 +26,10 @@
 // same call context of that function (and not split between caller and callee
 // contexts of a directly recursive call, for example).
 //
+// Additionally, these routines can't simplify to the instructions that are not
+// def-reachable, meaning we can't just scan the basic block for instructions
+// to simplify to.
+//
 //===----------------------------------------------------------------------===//
 
 #ifndef LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H

diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 7aecbe77dd54..ae4f2804f7af 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4403,6 +4403,10 @@ Value *llvm::SimplifyExtractElementInst(Value *Vec, Value *Idx,
 
 /// See if we can fold the given phi. If not, returns null.
 static Value *SimplifyPHINode(PHINode *PN, const SimplifyQuery &Q) {
+  // WARNING: no matter how worthwhile it may seem, we can not perform PHI CSE
+  //          here, because the PHI we may succeed simplifying to was not
+  //          def-reachable from the original PHI!
+
   // If all of the PHI's incoming values are the same then replace the PHI node
   // with the common value.
   Value *CommonValue = nullptr;


        


More information about the llvm-commits mailing list