From cb6d1820b8ffec7dfbc0727eba3250e48b1ff490 Mon Sep 17 00:00:00 2001 From: Evgeny Stupachenko Date: Fri, 4 Aug 2017 18:46:13 +0000 Subject: [PATCH] Fix PR33514 Summary: The bug was uncovered after fix of PR23384 (part 3 of 3). The patch restricts pointer multiplication in SCEV computaion for ICmpZero. Reviewers: qcolombet Differential Revision: http://reviews.llvm.org/D36170 From: Evgeny Stupachenko git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310092 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopStrengthReduce.cpp | 6 ++++++ test/Transforms/LoopStrengthReduce/pr27056.ll | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 38a7cf76949..d353bbd79f8 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -3672,6 +3672,12 @@ void LSRInstance::GenerateICmpZeroScales(LSRUse &LU, unsigned LUIdx, // Don't do this if there is more than one offset. if (LU.MinOffset != LU.MaxOffset) return; + // Check if transformation is valid. It is illegal to multiply pointer. + if (Base.ScaledReg && Base.ScaledReg->getType()->isPointerTy()) + return; + for (const SCEV *BaseReg : Base.BaseRegs) + if (BaseReg->getType()->isPointerTy()) + return; assert(!Base.BaseGV && "ICmpZero use is not legal!"); // Check each interesting stride. diff --git a/test/Transforms/LoopStrengthReduce/pr27056.ll b/test/Transforms/LoopStrengthReduce/pr27056.ll index 6a255f6f4e8..57dc8cd45fe 100644 --- a/test/Transforms/LoopStrengthReduce/pr27056.ll +++ b/test/Transforms/LoopStrengthReduce/pr27056.ll @@ -45,6 +45,7 @@ try.cont: ; preds = %for.end ; CHECK-LABEL: define void @b_copy_ctor( ; CHECK: catchpad ; CHECK-NEXT: icmp eq %struct.L -; CHECK-NEXT: getelementptr {{.*}} i64 sub (i64 0, i64 ptrtoint (%struct.L* @GV2 to i64)) +; CHECK-NEXT: %4 = sub i64 0, %1 +; CHECK-NEXT: getelementptr {{.*}} getelementptr inbounds (%struct.L, %struct.L* @GV2, i32 0, i32 0), i64 %4 declare void @a_copy_ctor() -- 2.50.1