[PATCH] D89978: Fix SROA with a constant value PHI

Stanislav Mekhanoshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 22 11:25:58 PDT 2020


rampitec created this revision.
rampitec added reviewers: arsenm, uabelho.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
rampitec requested review of this revision.
Herald added a subscriber: wdng.

This fixes the bug 47945. It is legal to have a PHI with values
from from the same block, but values must stay the same. In this
case it is illegal to merge different values.


https://reviews.llvm.org/D89978

Files:
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/test/Transforms/SROA/phi-gep.ll


Index: llvm/test/Transforms/SROA/phi-gep.ll
===================================================================
--- llvm/test/Transforms/SROA/phi-gep.ll
+++ llvm/test/Transforms/SROA/phi-gep.ll
@@ -452,6 +452,35 @@
   ret void
 }
 
+define void @constant_value_phi() {
+; CHECK-LABEL: @constant_value_phi(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br label [[LAND_LHS_TRUE_I:%.*]]
+; CHECK:       land.lhs.true.i:
+; CHECK-NEXT:    br i1 undef, label [[COND_END_I:%.*]], label [[COND_END_I]]
+; CHECK:       cond.end.i:
+; CHECK-NEXT:    unreachable
+;
+entry:
+  %s1 = alloca [3 x i16]
+  %s = alloca [3 x i16]
+  %cast = bitcast [3 x i16]* %s1 to i16*
+  br label %land.lhs.true.i
+
+land.lhs.true.i:                                  ; preds = %entry
+  br i1 undef, label %cond.end.i, label %cond.end.i
+
+cond.end.i:                                       ; preds = %land.lhs.true.i, %land.lhs.true.i
+  %.pre-phi1 = phi i16* [ %cast, %land.lhs.true.i ], [ %cast, %land.lhs.true.i ]
+  %cast2 = bitcast [3 x i16]* %s to i16*
+  call void @llvm.memcpy.p0i16.p0i16.i64(i16* %.pre-phi1, i16* %cast2, i64 3, i1 false)
+  %gep = getelementptr inbounds [3 x i16], [3 x i16]* %s, i32 0, i32 0
+  %load = load i16, i16* %gep
+  unreachable
+}
+
 declare %pair* @foo()
 
 declare i32 @__gxx_personality_v0(...)
+
+declare void @llvm.memcpy.p0i16.p0i16.i64(i16* noalias nocapture writeonly, i16* noalias nocapture readonly, i64, i1 immarg)
Index: llvm/lib/Transforms/Scalar/SROA.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SROA.cpp
+++ llvm/lib/Transforms/Scalar/SROA.cpp
@@ -3524,7 +3524,7 @@
       return false;
 
     PHINode *PHI = cast<PHINode>(GEPI.getPointerOperand());
-    if (GEPI.getParent() != PHI->getParent() ||
+    if (GEPI.getParent() != PHI->getParent() || PHI->hasConstantValue() ||
         llvm::any_of(PHI->incoming_values(), [](Value *In)
           { Instruction *I = dyn_cast<Instruction>(In);
             return !I || isa<GetElementPtrInst>(I) || isa<PHINode>(I) ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89978.300056.patch
Type: text/x-patch
Size: 2045 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201022/4fd06760/attachment.bin>


More information about the llvm-commits mailing list