[LPM] Fix a logic error in LICM spotted by inspection.
authorChandler Carruth <chandlerc@gmail.com>
Fri, 24 Jan 2014 02:24:47 +0000 (02:24 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Fri, 24 Jan 2014 02:24:47 +0000 (02:24 +0000)
We completely skipped promotion in LICM if the loop has a preheader or
dedicated exits, but not *both*. We hoist if there is a preheader, and
sink if there are dedicated exits, but either hoisting or sinking can
move loop invariant code out of the loop!

I have no idea if this has a practical consequence. If anyone has ideas
for a test case, let me know.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199966 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LICM.cpp

index f6c78b04f2fd88ba5fa243d3da42cfe66088b0e3..46d5ca3dcadade1f5204c5421d23221e9a3044e6 100644 (file)
@@ -273,7 +273,7 @@ bool LICM::runOnLoop(Loop *L, LPPassManager &LPM) {
 
   // Now that all loop invariants have been removed from the loop, promote any
   // memory references to scalars that we can.
-  if (!DisablePromotion && Preheader && L->hasDedicatedExits()) {
+  if (!DisablePromotion && (Preheader || L->hasDedicatedExits())) {
     SmallVector<BasicBlock *, 8> ExitBlocks;
     SmallVector<Instruction *, 8> InsertPts;