From c1b3e32118adff13bf846e0aa8b0b3b4ec04a120 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Sat, 29 Aug 2020 09:57:04 +0300 Subject: [PATCH] [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. --- llvm/include/llvm/Analysis/InstructionSimplify.h | 4 ++++ llvm/lib/Analysis/InstructionSimplify.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/llvm/include/llvm/Analysis/InstructionSimplify.h b/llvm/include/llvm/Analysis/InstructionSimplify.h index 7a69d20..6f3d168 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 7aecbe7..ae4f280 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; -- 2.7.4