From d9e88f7b7fef8f1a3dd48cf245365b65cc330eb5 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Fri, 15 Mar 2019 12:17:36 +0000 Subject: [LSR] Check for signed overflow in NarrowSearchSpaceByDetectingSupersets. We are adding a sign extended IR value to an int64_t, which can cause signed overflows, as in the attached test case, where we have a formula with BaseOffset = -1 and a constant with numeric_limits::min(). If the addition would overflow, skip the simplification for this formula. Note that the target triple is required to trigger the failure. Reviewers: qcolombet, gilr, kparzysz, efriedma Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D59211 llvm-svn: 356256 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp') diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index e4b9c44ea84..340f5db4bdb 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -4423,7 +4423,9 @@ void LSRInstance::NarrowSearchSpaceByDetectingSupersets() { I = F.BaseRegs.begin(), E = F.BaseRegs.end(); I != E; ++I) { if (const SCEVConstant *C = dyn_cast(*I)) { Formula NewF = F; - NewF.BaseOffset += C->getValue()->getSExtValue(); + //FIXME: Formulas should store bitwidth to do wrapping properly. + // See PR41034. + NewF.BaseOffset += (uint64_t)C->getValue()->getSExtValue(); NewF.BaseRegs.erase(NewF.BaseRegs.begin() + (I - F.BaseRegs.begin())); if (LU.HasFormulaWithSameRegs(NewF)) { -- cgit v1.2.3