Conan_Kudo / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone

Blame patches/llvm_host/llvm-0004-Fix-ScalarEvolutionExpander-step-scaling-bug.patch

Lucio Andrés Illanes Albornoz (arab, vxp) 585426
From c8ce9e59a883f452bc538b5f16fb83649472dc3e Mon Sep 17 00:00:00 2001
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
From: Keno Fischer <kfischer@college.harvard.edu>
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Date: Wed, 13 Jul 2016 01:28:12 +0000
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Subject: [PATCH] Fix ScalarEvolutionExpander step scaling bug
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
The expandAddRecExprLiterally function incorrectly transforms
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
`[Start + Step * X]` into `Step * [Start + X]` instead of the correct
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
transform of `[Step * X] + Start`.
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
This caused https://github.com/JuliaLang/julia/issues/14704#issuecomment-174126219
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
due to what appeared to be sufficiently complicated loop interactions.
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Patch by Jameson Nash (jameson@juliacomputing.com).
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Reviewers: sanjoy
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Differential Revision: http://reviews.llvm.org/D16505
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275239 91177308-0d34-0410-b5e6-96231b3b80d8
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Alpine maintainer notes:
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
This patch replaces deps/patches/llvm-3.7.1_3.patch from Julia.
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
---
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 lib/Analysis/ScalarEvolutionExpander.cpp           |  7 ++++
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 .../ScalarEvolution/incorrect-offset-scaling.ll    | 48 ++++++++++++++++++++++
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 2 files changed, 55 insertions(+)
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 create mode 100644 test/Analysis/ScalarEvolution/incorrect-offset-scaling.ll
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
index 7716435..77e4ec7 100644
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
--- a/lib/Analysis/ScalarEvolutionExpander.cpp
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+++ b/lib/Analysis/ScalarEvolutionExpander.cpp
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
@@ -1288,6 +1288,13 @@ Value *SCEVExpander::expandAddRecExprLiterally(const SCEVAddRecExpr *S) {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
   if (!SE.dominates(Step, L->getHeader())) {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
     PostLoopScale = Step;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
     Step = SE.getConstant(Normalized->getType(), 1);
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+    if (!Start->isZero()) {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+        // The normalization below assumes that Start is constant zero, so if
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+        // it isn't re-associate Start to PostLoopOffset.
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+        assert(!PostLoopOffset && "Start not-null but PostLoopOffset set?");
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+        PostLoopOffset = Start;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+        Start = SE.getConstant(Normalized->getType(), 0);
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+    }
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
     Normalized =
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
       cast<SCEVAddRecExpr>(SE.getAddRecExpr(
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
                              Start, Step, Normalized->getLoop(),
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
diff --git a/test/Analysis/ScalarEvolution/incorrect-offset-scaling.ll b/test/Analysis/ScalarEvolution/incorrect-offset-scaling.ll
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
new file mode 100644
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
index 0000000..7ffb093
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
--- /dev/null
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+++ b/test/Analysis/ScalarEvolution/incorrect-offset-scaling.ll
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
@@ -0,0 +1,48 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+; RUN: opt -S -loop-reduce < %s | FileCheck %s
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+target triple = "x86_64-unknown-unknown"
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+define void @incorrect_offset_scaling(i64, i64*) {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+top:
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  br label %L
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+L:                                                ; preds = %idxend.10, %idxend, %L2, %top
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  br i1 undef, label %L, label %L1
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+L1:                                               ; preds = %L1.preheader, %L2
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  %r13 = phi i64 [ %r1, %L2 ], [ 1, %L ]
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+; CHECK:  %lsr.iv = phi i64 [ 0, %L{{[^ ]+}} ], [ %lsr.iv.next, %L2 ]
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+; CHECK-NOT:  %lsr.iv = phi i64 [ -1, %L{{[^ ]+}} ], [ %lsr.iv.next, %L2 ]
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+; CHECK:  br
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  %r0 = add i64 %r13, -1
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  br label %idxend.8
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+L2:                                               ; preds = %idxend.8
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  %r1 = add i64 %r13, 1
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  br i1 undef, label %L, label %L1
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+if6:                                              ; preds = %idxend.8
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  %r2 = add i64 %0, -1
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  %r3 = load i64, i64* %1, align 8
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+; CHECK-NOT:  %r2
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+; CHECK:  %r3 = load i64
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  br label %ib
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+idxend.8:                                         ; preds = %L1
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  br i1 undef, label %if6, label %L2
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+ib:                                               ; preds = %if6
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  %r4 = mul i64 %r3, %r0
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  %r5 = add i64 %r2, %r4
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  %r6 = icmp ult i64 %r5, undef
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+; CHECK  %2 = mul i64 %lsr.iv, %r3
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+; CHECK  %3 = add i64 %1, -1
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+; CHECK  %4 = add i64 %0, %r3
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+; CHECK  %r6
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  %r7 = getelementptr i64, i64* undef, i64 %r5
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  store i64 1, i64* %r7, align 8
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+; CHECK  %5 = mul i64 %lsr.iv, %r3
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+; CHECK  %6 = add i64 %5, -1
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  br label %L
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+}