[PATCH] D36170: LSR: Fix PR33514

Evgeny Stupachenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 1 12:56:21 PDT 2017


evstupac created this revision.
Herald added a subscriber: mzolotukhin.

The patch restrict multiplication of ICmpZero formula by any constant if there is a pointer type register (p) in the formula.
If not restricted it can potentially cause expand of SCEV :  C * p, which is undefined (if C != 1 or 0).


Repository:
  rL LLVM

https://reviews.llvm.org/D36170

Files:
  lib/Transforms/Scalar/LoopStrengthReduce.cpp
  test/Transforms/LoopStrengthReduce/pr27056.ll


Index: lib/Transforms/Scalar/LoopStrengthReduce.cpp
===================================================================
--- lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -3646,6 +3646,12 @@
   // 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.
Index: test/Transforms/LoopStrengthReduce/pr27056.ll
===================================================================
--- test/Transforms/LoopStrengthReduce/pr27056.ll
+++ test/Transforms/LoopStrengthReduce/pr27056.ll
@@ -45,6 +45,7 @@
 ; 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()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36170.109184.patch
Type: text/x-patch
Size: 1306 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170801/6e767b08/attachment.bin>


More information about the llvm-commits mailing list