[llvm-commits] [llvm] r153176 - /llvm/trunk/lib/Analysis/InstructionSimplify.cpp

Chandler Carruth chandlerc at gmail.com
Wed Mar 21 03:58:48 PDT 2012


Author: chandlerc
Date: Wed Mar 21 05:58:47 2012
New Revision: 153176

URL: http://llvm.org/viewvc/llvm-project?rev=153176&view=rev
Log:
Teach instsimplify to gracefully degrade in the presence of instructions
not attched to a basic block or function. There are conservatively
correct answers in these cases, and this makes the analysis more useful
in contexts where we have a partially formed bit of IR.

I don't have any way to test this directly... suggestions welcome here,
but I'm not seeing anything sadly. I only found this using a subsequent
patch to the inliner which runs instsimplify on partially inlined
instructions, and even then only on a quite large program. I never got
a reasonable testcase out of it, and anything I do get is likely to be
quite fragile due to requiring an interaction of two different passes,
and the only result being a segfault if it goes wrong.

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=153176&r1=153175&r2=153176&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Wed Mar 21 05:58:47 2012
@@ -95,6 +95,12 @@
     // Arguments and constants dominate all instructions.
     return true;
 
+  // If we are processing instructions (and/or basic blocks) that have not been
+  // fully added to a function, the parent nodes may still be null. Simply
+  // return the conservative answer in these cases.
+  if (!I->getParent() || !P->getParent() || !I->getParent()->getParent())
+    return false;
+
   // If we have a DominatorTree then do a precise test.
   if (DT) {
     if (!DT->isReachableFromEntry(P->getParent()))





More information about the llvm-commits mailing list