Index: lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp =================================================================== --- lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp +++ lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp @@ -79,6 +79,9 @@ static cl::opt SkipProfitabilityChecks("irce-skip-profitability-checks", cl::Hidden, cl::init(false)); +static cl::opt AllowUnsignedLatchCondition("irce-allow-unsigned-latch", + cl::Hidden, cl::init(false)); + static const char *ClonedLoopTag = "irce.loop.clone"; #define DEBUG_TYPE "irce" @@ -889,6 +892,15 @@ IsSignedPredicate = Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SGT; + + // FIXME: We temporarily disable unsigned latch conditions by default + // because of found problems with intersecting signed and unsigned ranges. + // We are going to turn it on once the problems are fixed. + if (!IsSignedPredicate && !AllowUnsignedLatchCondition) { + FailureReason = "unsigned latch conditions are explicitly prohibited"; + return None; + } + // The predicate that we need to check that the induction variable lies // within bounds. ICmpInst::Predicate BoundPred = @@ -964,6 +976,15 @@ IsSignedPredicate = Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SGT; + + // FIXME: We temporarily disable unsigned latch conditions by default + // because of found problems with intersecting signed and unsigned ranges. + // We are going to turn it on once the problems are fixed. + if (!IsSignedPredicate && !AllowUnsignedLatchCondition) { + FailureReason = "unsigned latch conditions are explicitly prohibited"; + return None; + } + // The predicate that we need to check that the induction variable lies // within bounds. ICmpInst::Predicate BoundPred = Index: test/Transforms/IRCE/clamp.ll =================================================================== --- test/Transforms/IRCE/clamp.ll +++ test/Transforms/IRCE/clamp.ll @@ -1,4 +1,4 @@ -; RUN: opt -verify-loop-info -irce-print-changed-loops -irce -S < %s 2>&1 | FileCheck %s +; RUN: opt -verify-loop-info -irce-print-changed-loops -irce -irce-allow-unsigned-latch=true -S < %s 2>&1 | FileCheck %s ; The test demonstrates that incorrect behavior of Clamp may lead to incorrect ; calculation of post-loop exit condition. Index: test/Transforms/IRCE/eq_ne.ll =================================================================== --- test/Transforms/IRCE/eq_ne.ll +++ test/Transforms/IRCE/eq_ne.ll @@ -1,4 +1,4 @@ -; RUN: opt -verify-loop-info -irce-print-changed-loops -irce -S < %s 2>&1 | FileCheck %s +; RUN: opt -verify-loop-info -irce-print-changed-loops -irce -irce-allow-unsigned-latch=true -S < %s 2>&1 | FileCheck %s ; CHECK: irce: in function test_01: constrained Loop at depth 1 containing: %loop
,%in.bounds ; CHECK: irce: in function test_01u: constrained Loop at depth 1 containing: %loop
,%in.bounds Index: test/Transforms/IRCE/stride_more_than_1.ll =================================================================== --- test/Transforms/IRCE/stride_more_than_1.ll +++ test/Transforms/IRCE/stride_more_than_1.ll @@ -1,4 +1,4 @@ -; RUN: opt -verify-loop-info -irce-print-changed-loops -irce -S < %s 2>&1 | FileCheck %s +; RUN: opt -verify-loop-info -irce-print-changed-loops -irce -irce-allow-unsigned-latch=true -S < %s 2>&1 | FileCheck %s ; CHECK: irce: in function test_01: constrained Loop at depth 1 containing: %loop
,%in.bounds ; CHECK: irce: in function test_02: constrained Loop at depth 1 containing: %loop
,%in.bounds Index: test/Transforms/IRCE/unsigned_comparisons_ugt.ll =================================================================== --- test/Transforms/IRCE/unsigned_comparisons_ugt.ll +++ test/Transforms/IRCE/unsigned_comparisons_ugt.ll @@ -1,4 +1,4 @@ -; RUN: opt -verify-loop-info -irce-print-changed-loops -irce -S < %s 2>&1 | FileCheck %s +; RUN: opt -verify-loop-info -irce-print-changed-loops -irce -irce-allow-unsigned-latch=true -S < %s 2>&1 | FileCheck %s ; CHECK: irce: in function test_01: constrained Loop at depth 1 containing: %loop
,%in.bounds ; CHECK: irce: in function test_02: constrained Loop at depth 1 containing: %loop
,%in.bounds Index: test/Transforms/IRCE/unsigned_comparisons_ult.ll =================================================================== --- test/Transforms/IRCE/unsigned_comparisons_ult.ll +++ test/Transforms/IRCE/unsigned_comparisons_ult.ll @@ -1,4 +1,4 @@ -; RUN: opt -verify-loop-info -irce-print-changed-loops -irce -S < %s 2>&1 | FileCheck %s +; RUN: opt -verify-loop-info -irce-print-changed-loops -irce -irce-allow-unsigned-latch=true -S < %s 2>&1 | FileCheck %s ; CHECK: irce: in function test_01: constrained Loop at depth 1 containing: %loop
,%in.bounds ; CHECK: irce: in function test_02: constrained Loop at depth 1 containing: %loop
,%in.bounds