llvm-project/llvm/lib/Transforms/Utils
Gerolf Hoflehner 2432bd0ddd [SimplifyCFG] Fix for "endless" loop after dead code removal (Alternative to
D16251)

Summary:
This is a simpler fix to the problem than the dominator approach in
http://reviews.llvm.org/D16251. It adds only values into the gather() while loop
that have been seen before.

The actual endless loop is in the constant compare gather() routine in
Utils/SimplifyCFG.cpp. The same value ret.0.off0.i is pushed back into the
queue:
%.ret.0.off0.i = or i1 %.ret.0.off0.i, %cmp10.i

Here is what happens at the IR level:

for.cond.i:                                       ; preds = %if.end6.i,
%if.end.i54
%ix.0.i = phi i32 [ 0, %if.end.i54 ], [ %inc.i55, %if.end6.i ]
%ret.0.off0.i = phi i1 [false, %if.end.i54], [%.ret.0.off0.i, %if.end6.i] <<<
%cmp2.i = icmp ult i32 %ix.0.i, %11
br i1 %cmp2.i, label %for.body.i, label %LBJ_TmpSimpleNeedExt.exit

if.end6.i:                                        ; preds = %for.body.i
%cmp10.i = icmp ugt i32 %conv.i, %add9.i
%.ret.0.off0.i = or i1 %ret.0.off0.i, %cmp10.i <<<

When if.end.i54 gets eliminated which removes the definition of ret.0.off0.i.
The result is the expression %.ret.0.off0.i = or i1 %.ret.0.off0.i, %cmp10.i
(Note the first ‘or’ operand is now %.ret.0.off0.i, and *NOT* %ret.0.off0.i).
And
now there is use of .ret.0.off0.i before a definition which triggers the
“endless” loop in gather():

while(!DFT.empty()) {

    V = DFT.pop_back_val();   // V is .ret.0.off0.i

    if (Instruction *I = dyn_cast<Instruction>(V)) {
      // If it is a || (or && depending on isEQ), process the operands.
      if (I->getOpcode() == (isEQ ? Instruction::Or : Instruction::And)) {
        DFT.push_back(I->getOperand(1));  // This is now .ret.0.off0.i also
        DFT.push_back(I->getOperand(0));

        continue; // “endless loop” for .ret.0.off0.i
      }

Reviewers: reames, ahatanak

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D16839

llvm-svn: 259730
2016-02-03 23:54:25 +00:00
..
ASanStackFrameLayout.cpp Update to use new name alignTo(). 2016-01-14 21:06:47 +00:00
AddDiscriminators.cpp Fix Clang-tidy modernize-use-nullptr and modernize-use-override warnings; other minor fixes. 2016-01-26 18:48:36 +00:00
BasicBlockUtils.cpp [SplitLandingPadPredecessors] Create a PHINode for the original landingpad only if it has some uses 2016-01-06 20:32:05 +00:00
BreakCriticalEdges.cpp TransformUtils: Remove implicit ilist iterator conversions, NFC 2015-10-13 02:39:05 +00:00
BuildLibCalls.cpp Fix Clang-tidy readability-redundant-control-flow warnings; other minor fixes. 2016-02-02 18:20:45 +00:00
BypassSlowDivision.cpp Clarify that the bypassSlowDivision optimization operates on a single BB [v2] 2016-01-04 23:18:58 +00:00
CMakeLists.txt Transforms: Move GlobalOpt's Evaluator to Utils where it can be reused. 2016-02-03 02:51:00 +00:00
CloneFunction.cpp Remove CloningDirector and associated code 2016-01-08 18:23:17 +00:00
CloneModule.cpp GlobalValue: use getValueType() instead of getType()->getPointerElementType(). 2016-01-16 20:30:46 +00:00
CmpInstAnalysis.cpp [C++] Use 'nullptr'. Transforms edition. 2014-04-25 05:29:35 +00:00
CodeExtractor.cpp [IR] Reformulate LLVM's EH funclet IR 2015-12-12 05:38:55 +00:00
CtorUtils.cpp TransformUtils: Remove implicit ilist iterator conversions, NFC 2015-10-13 02:39:05 +00:00
DemoteRegToStack.cpp TransformUtils: Remove implicit ilist iterator conversions, NFC 2015-10-13 02:39:05 +00:00
Evaluator.cpp Add #include "llvm/Support/raw_ostream.h" to fix Windows build. 2016-02-03 03:16:37 +00:00
FlattenCFG.cpp LPM: Stop threading `Pass *` through all of the loop utility APIs. NFC 2015-12-15 19:40:57 +00:00
GlobalStatus.cpp GlobalOpt does not treat externally_initialized globals correctly 2015-10-12 13:20:52 +00:00
InlineFunction.cpp [Inliner/WinEH] Honor implicit nounwinds 2016-01-20 02:15:15 +00:00
InstructionNamer.cpp Revert r240137 (Fixed/added namespace ending comments using clang-tidy. NFC) 2015-06-23 09:49:53 +00:00
IntegerDivision.cpp [Transforms] Use asserts instead of ifs around llvm_unreachable. NFC 2015-12-25 02:04:17 +00:00
LCSSA.cpp [WinEH] Update LCSSA to handle catchswitch with handlers inside and outside a loop 2015-12-18 18:12:35 +00:00
LLVMBuild.txt [PM/AA] Remove the last relics of the separate IPA library from LLVM, 2015-08-18 17:51:53 +00:00
Local.cpp Avoid overly large SmallPtrSet/SmallSet 2016-01-30 01:24:31 +00:00
LoopSimplify.cpp [LoopSimplify] Reuse changeToUnreachable 2016-01-24 19:32:52 +00:00
LoopUnroll.cpp LoopInfo: Simplify ownership of Loop objects 2016-01-08 19:08:53 +00:00
LoopUnrollRuntime.cpp Minor code formatting cleanup. NFC. 2016-01-28 01:23:18 +00:00
LoopUtils.cpp function names start with a lower case letter ; NFC 2016-01-12 18:03:37 +00:00
LoopVersioning.cpp [LoopVersioning] Expose loop versioning as a pass too 2016-02-03 00:06:10 +00:00
LowerInvoke.cpp TransformUtils: Remove implicit ilist iterator conversions, NFC 2015-10-13 02:39:05 +00:00
LowerSwitch.cpp TransformUtils: Remove implicit ilist iterator conversions, NFC 2015-10-13 02:39:05 +00:00
Mem2Reg.cpp [Mem2Reg] Respect optnone 2015-12-11 13:36:59 +00:00
MemorySSA.cpp Attempt #2 to unbreak r259595. 2016-02-02 23:26:01 +00:00
MetaRenamer.cpp Whoops, remove trailing whitespace. 2015-08-27 05:37:12 +00:00
ModuleUtils.cpp GlobalValue: use getValueType() instead of getType()->getPointerElementType(). 2016-01-16 20:30:46 +00:00
PromoteMemoryToRegister.cpp getParent() ^ 3 == getModule() ; NFCI 2015-12-14 17:24:23 +00:00
SSAUpdater.cpp Revert r240137 (Fixed/added namespace ending comments using clang-tidy. NFC) 2015-06-23 09:49:53 +00:00
SanitizerStats.cpp Fix Clang-tidy modernize-use-nullptr and modernize-use-override warnings; other minor fixes. 2016-01-26 18:48:36 +00:00
SimplifyCFG.cpp [SimplifyCFG] Fix for "endless" loop after dead code removal (Alternative to 2016-02-03 23:54:25 +00:00
SimplifyIndVar.cpp LPM: Stop threading `Pass *` through all of the loop utility APIs. NFC 2015-12-15 19:40:57 +00:00
SimplifyInstructions.cpp [Utils] Put includes in correct order. NFC. 2015-11-24 18:57:06 +00:00
SimplifyLibCalls.cpp [LibCallSimplifier] fold memset(malloc(x), 0, x) --> calloc(1, x) 2016-01-26 16:17:24 +00:00
SplitModule.cpp Avoid overly large SmallPtrSet/SmallSet 2016-01-30 01:24:31 +00:00
SymbolRewriter.cpp Make some headers self-contained, remove unused includes that violate layering. 2016-01-27 16:05:37 +00:00
UnifyFunctionExitNodes.cpp TransformUtils: Remove implicit ilist iterator conversions, NFC 2015-10-13 02:39:05 +00:00
Utils.cpp This patch adds MemorySSA to LLVM. 2016-02-02 22:46:49 +00:00
ValueMapper.cpp Split resolveCycles(bool AllowTemps) into two interfaces and document 2016-01-11 21:37:41 +00:00