D51639-optim-issue
authorLLVM Packaging Team <pkg-llvm-team@lists.alioth.debian.org>
Sat, 9 Mar 2019 06:10:15 +0000 (06:10 +0000)
committerMo Zhou <cdluminate@gmail.com>
Sat, 9 Mar 2019 06:10:15 +0000 (06:10 +0000)
===================================================================

Gbp-Pq: Name D51639-optim-issue.diff

lib/Transforms/Vectorize/LoopVectorize.cpp
test/Transforms/LoopVectorize/X86/uniform-phi.ll

index 5bcf0c0a7ba6364bd0bbae1a20d5ac09d1336853..e84b3c35e11c5918ca20c9001b40c5df977317ff 100644 (file)
@@ -5770,6 +5770,11 @@ void LoopVectorizationCostModel::collectLoopUniforms(unsigned VF) {
     for (auto OV : I->operand_values()) {
       if (isOutOfScope(OV))
         continue;
+      // First order recurrence Phi's should typically be considered
+      // non-uniform.
+      auto *OP = dyn_cast<PHINode>(OV);
+      if (OP && Legal->isFirstOrderRecurrence(OP))
+        continue;
       auto *OI = cast<Instruction>(OV);
       if (llvm::all_of(OI->users(), [&](User *U) -> bool {
             auto *J = cast<Instruction>(U);
index 881f29a94cb50389e12fda7be36b8732cbff1899..2be565e71105c66daec079f31e1e6be595f2abe4 100644 (file)
@@ -75,3 +75,25 @@ for.end:                                          ; preds = %for.body
   ret i64 %retval
 }
 
+; CHECK-LABEL: PR38786
+; Check that first order recurrence phis (%phi32 and %phi64) are not uniform.
+; CHECK-NOT: LV: Found uniform instruction:   %phi
+define void @PR38786(double* %y, double* %x, i64 %n) {
+entry:
+  br label %for.body
+
+for.body:
+  %phi32 = phi i32 [ 0, %entry ], [ %i32next, %for.body ]
+  %phi64 = phi i64 [ 0, %entry ], [ %i64next, %for.body ]
+  %i32next = add i32 %phi32, 1
+  %i64next = zext i32 %i32next to i64
+  %xip = getelementptr inbounds double, double* %x, i64 %i64next
+  %yip = getelementptr inbounds double, double* %y, i64 %phi64
+  %xi = load double, double* %xip, align 8
+  store double %xi, double* %yip, align 8
+  %cmp = icmp slt i64 %i64next, %n
+  br i1 %cmp, label %for.body, label %for.end
+
+for.end:
+  ret void
+}