Index: lib/Transforms/Scalar/LoopStrengthReduce.cpp =================================================================== --- lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -3598,7 +3598,12 @@ if (InsertFormula(LU, LUIdx, F)) // If that formula hadn't been seen before, recurse to find more like // it. - GenerateReassociations(LU, LUIdx, LU.Formulae.back(), Depth + 1); + // Add check on Log16(AddOps.size()) - same as Log2_32(AddOps.size()) >> 2) + // Because just Depth is not enough to bound compile time. + // This means that every time AddOps.size() is greater 16^x we will add + // x to Depth. + GenerateReassociations(LU, LUIdx, LU.Formulae.back(), + Depth + 1 + (Log2_32(AddOps.size()) >> 2)); } } Index: test/Transforms/LoopStrengthReduce/lsr-comp-time.ll =================================================================== --- test/Transforms/LoopStrengthReduce/lsr-comp-time.ll +++ test/Transforms/LoopStrengthReduce/lsr-comp-time.ll @@ -0,0 +1,2198 @@ +; RUN: opt -loop-reduce -disable-output < %s +; Test checks compile time is reasonable (no hang for ~10 minutes). + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + +@.str = private unnamed_addr constant [21 x i8] c"%u %u %u %u %u %u %u\00", align 1 +@.str.1 = private unnamed_addr constant [10 x i8] c"res = %u\0A\00", align 1 + +; Function Attrs: norecurse nounwind uwtable +define dso_local void @init(i32* nocapture, i32, i32) local_unnamed_addr #0 { + %4 = icmp eq i32 %1, 0 + br i1 %4, label %101, label %5 + +;