aboutsummaryrefslogtreecommitdiffstats
path: root/main/llvm
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2016-08-18 17:51:28 +0200
committerCarlo Landmeter <clandmeter@gmail.com>2016-08-18 23:01:39 +0200
commit5a96754dfb25d723a30abff1380973e0f4e71131 (patch)
tree5229f95ae64637e6361365e762736bec2cf9f4e3 /main/llvm
parent0b05a2cbb063e51d1e9452467c7ba2bf4e0b4aff (diff)
downloadaports-5a96754dfb25d723a30abff1380973e0f4e71131.tar.bz2
aports-5a96754dfb25d723a30abff1380973e0f4e71131.tar.xz
main/llvm: backport upstream patches required by Julia
All of the patches are taken directly from the LLVM upstream, master branch.
Diffstat (limited to 'main/llvm')
-rw-r--r--main/llvm/APKBUILD22
-rw-r--r--main/llvm/llvm-0004-Fix-ScalarEvolutionExpander-step-scaling-bug.patch99
-rw-r--r--main/llvm/llvm-0005-optimize-store-of-bitcast-from-vector-to-aggregate.patch181
-rw-r--r--main/llvm/llvm-0006-clone-every-functions-debug-info.patch129
-rw-r--r--main/llvm/llvm-0007-reduce-complexity-of-debug-info-clonning-and-fix-correctness.patch102
-rw-r--r--main/llvm/llvm-0008-dont-widen-metadata-on-store-to-load-forwarding.patch107
6 files changed, 639 insertions, 1 deletions
diff --git a/main/llvm/APKBUILD b/main/llvm/APKBUILD
index 92366aec1f..22220afab2 100644
--- a/main/llvm/APKBUILD
+++ b/main/llvm/APKBUILD
@@ -2,7 +2,7 @@
# Maintainer: Travis Tilley <ttilley@gmail.com>
pkgname=llvm
pkgver=3.8.1
-pkgrel=0
+pkgrel=1
pkgdesc="Low Level Virtual Machine compiler system"
arch="all"
url="http://llvm.org/"
@@ -31,6 +31,11 @@ source="http://llvm.org/releases/$pkgver/llvm-$pkgver.src.tar.xz
llvm-0001-Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch
llvm-0002-Fix-build-with-musl-libc.patch
llvm-0003-Fix-DynamicLibrary-to-build-with-musl-libc.patch
+ llvm-0004-Fix-ScalarEvolutionExpander-step-scaling-bug.patch
+ llvm-0005-optimize-store-of-bitcast-from-vector-to-aggregate.patch
+ llvm-0006-clone-every-functions-debug-info.patch
+ llvm-0007-reduce-complexity-of-debug-info-clonning-and-fix-correctness.patch
+ llvm-0008-dont-widen-metadata-on-store-to-load-forwarding.patch
llvm-nm-workaround.patch
llvm-exit-config-when-cbuild-set.patch
"
@@ -144,17 +149,32 @@ md5sums="538467e6028bbc9259b1e6e015d25845 llvm-3.8.1.src.tar.xz
10904f363abd86c5c4729e5630ea319c llvm-0001-Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch
b0cd098117223159b76e96c3f884536b llvm-0002-Fix-build-with-musl-libc.patch
9cc5050619f764ca9dc842a5ab122290 llvm-0003-Fix-DynamicLibrary-to-build-with-musl-libc.patch
+1485f62f8b26541a5308b082e9172de9 llvm-0004-Fix-ScalarEvolutionExpander-step-scaling-bug.patch
+ade897d81b5ed522fa07bf045e779cbc llvm-0005-optimize-store-of-bitcast-from-vector-to-aggregate.patch
+fc5ac9c103c97057526a0c98e965199d llvm-0006-clone-every-functions-debug-info.patch
+c06093bf71dba5edc87e3b1a2ea69b40 llvm-0007-reduce-complexity-of-debug-info-clonning-and-fix-correctness.patch
+1646fff7966d8e727ff20e3891372e4f llvm-0008-dont-widen-metadata-on-store-to-load-forwarding.patch
785147afd8ab80fa95955a5637b6582f llvm-nm-workaround.patch
79d98688de62404b6276e3aa2ea01b01 llvm-exit-config-when-cbuild-set.patch"
sha256sums="6e82ce4adb54ff3afc18053d6981b6aed1406751b8742582ed50f04b5ab475f9 llvm-3.8.1.src.tar.xz
708db2b21570e48e2c2e155a0c7b7969acecbb82393e306b5b69b0353ac108dd llvm-0001-Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch
e1b0fd5f6918d8c8404f3ec4b8d3ab8fbe8dadc2d6011792349b56e5e8ee51e2 llvm-0002-Fix-build-with-musl-libc.patch
fc28356bf0d5fcfe9b99e28f4abbc2f49f50d263b44e428e30f33bf5472747b4 llvm-0003-Fix-DynamicLibrary-to-build-with-musl-libc.patch
+a12615f51d4ebfc724bd6075dbab62b1632f42c9daed3f1e2d279e4985a7ccda llvm-0004-Fix-ScalarEvolutionExpander-step-scaling-bug.patch
+8c7571fddebd073f81efb11a489def1cfdfbd77ba202fec71d6955c4c52fffa1 llvm-0005-optimize-store-of-bitcast-from-vector-to-aggregate.patch
+1d109e00c6c904d0af5a4cc49b5fb0a5b895890ebdd3e3a1bc5d517e162afc1f llvm-0006-clone-every-functions-debug-info.patch
+18e00ea15872e672a17b4797a88cea0d3fb4d80c5557455cc1e8e8f5ddda13d6 llvm-0007-reduce-complexity-of-debug-info-clonning-and-fix-correctness.patch
+4c27b11af5d6e2b0c5a2c4e5b3dd49ef1b2aea9f5d55af72f75582de13bffefa llvm-0008-dont-widen-metadata-on-store-to-load-forwarding.patch
1870f910a6f5f2ba6144bd079ec55ed879fe8fd8b1b1b384935f36da43e5f114 llvm-nm-workaround.patch
8dca08e97637ae1ce5c99d8a6f7fefec9869ea1cda22fe33fe8ebd0a489d0df3 llvm-exit-config-when-cbuild-set.patch"
sha512sums="99bbb2cc5f337fd5edf1621f8028c8cb74011aa4af2531018dc05409b27f7b8d0c2f76a00115f677f7c013029d5d9f55d085a5b40433409aac4e9161d53bd366 llvm-3.8.1.src.tar.xz
a97ad7a71ec4878f1a8a335dbc0c161323d957aeb95917b0c4837405c69b53b5f9718094e0e9fd7814c74f44aaa8cff3a9379202964b537c8162a53214621bc5 llvm-0001-Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch
4cb3fabbb627b596ce398ed717c66ad20bbea7092ba30751520cc5a63d38e1ac53d23e98a6ad82121ddcf2434383ba5cadbc2990f99a4528e99c6e2160c2f725 llvm-0002-Fix-build-with-musl-libc.patch
19bfb9282455d39d07dbb2b1293b03a45c57d522fbb9c5e58dac034200669628b97e7a90cd4ff5d52d9bb79acfccbef653d8a1140a7f0589ecd6f9b7c4ba0eb6 llvm-0003-Fix-DynamicLibrary-to-build-with-musl-libc.patch
+f1cbbe0fc39151749ef5423619eb2855905535b2aaab5e6659bacfb14818e56c6b2205f258604db009dcfb1eebd51588a39fc76e1ec5421d68fde1fe65fab550 llvm-0004-Fix-ScalarEvolutionExpander-step-scaling-bug.patch
+199565f088605e758d12fb17ba556463a3b6f523a0629949b3de2f5eb4a34775d7390ff3842f97f30a4828185c611ae8534b2f7beff17fa35bbd928478c2c069 llvm-0005-optimize-store-of-bitcast-from-vector-to-aggregate.patch
+3f4625dab896f27645a45f2fa75efb2b25ee249379b110e7510b8908e7f16edf14907d431bacd8c5dc2821fd5740f3091c881d31c2d44a6aa415e6d06cd5d7f0 llvm-0006-clone-every-functions-debug-info.patch
+3e9de70c000dfbf0e405d85607e10f2c61c608df957c6195560b9f4b583ddf4be30538846d86bee02038b23f9deedd773dccd24c3fee89a942a3e5e1f3d0ad4a llvm-0007-reduce-complexity-of-debug-info-clonning-and-fix-correctness.patch
+6bb3e8e1b794737b1f411b5656f1a8e13e696c3c0cc8cb57297b371746713948f07c5c4fa93b57f90125f0da82550c1b6973e64575b636092d75fa05694610d2 llvm-0008-dont-widen-metadata-on-store-to-load-forwarding.patch
11db6f3c5d697bc536c7d053530f7a5572756185e16399c32c31306861b58046ca9bc14b8d8097758c00a8c1a7026cbfb75636c0e697e59c53dda5848f93b006 llvm-nm-workaround.patch
7a162897c0014ca7c0415edf8e2ab477c964a451db63a4a9a5852ad58e238da003fca9e821bf3cc130e0684ce03e0f2eee7371f819d5282be82b1876d49c52e4 llvm-exit-config-when-cbuild-set.patch"
diff --git a/main/llvm/llvm-0004-Fix-ScalarEvolutionExpander-step-scaling-bug.patch b/main/llvm/llvm-0004-Fix-ScalarEvolutionExpander-step-scaling-bug.patch
new file mode 100644
index 0000000000..9945bf3567
--- /dev/null
+++ b/main/llvm/llvm-0004-Fix-ScalarEvolutionExpander-step-scaling-bug.patch
@@ -0,0 +1,99 @@
+From c8ce9e59a883f452bc538b5f16fb83649472dc3e Mon Sep 17 00:00:00 2001
+From: Keno Fischer <kfischer@college.harvard.edu>
+Date: Wed, 13 Jul 2016 01:28:12 +0000
+Subject: [PATCH] Fix ScalarEvolutionExpander step scaling bug
+
+The expandAddRecExprLiterally function incorrectly transforms
+`[Start + Step * X]` into `Step * [Start + X]` instead of the correct
+transform of `[Step * X] + Start`.
+
+This caused https://github.com/JuliaLang/julia/issues/14704#issuecomment-174126219
+due to what appeared to be sufficiently complicated loop interactions.
+
+Patch by Jameson Nash (jameson@juliacomputing.com).
+
+Reviewers: sanjoy
+Differential Revision: http://reviews.llvm.org/D16505
+
+git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275239 91177308-0d34-0410-b5e6-96231b3b80d8
+
+Alpine maintainer notes:
+This patch replaces deps/patches/llvm-3.7.1_3.patch from Julia.
+---
+ lib/Analysis/ScalarEvolutionExpander.cpp | 7 ++++
+ .../ScalarEvolution/incorrect-offset-scaling.ll | 48 ++++++++++++++++++++++
+ 2 files changed, 55 insertions(+)
+ create mode 100644 test/Analysis/ScalarEvolution/incorrect-offset-scaling.ll
+
+diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp
+index 7716435..77e4ec7 100644
+--- a/lib/Analysis/ScalarEvolutionExpander.cpp
++++ b/lib/Analysis/ScalarEvolutionExpander.cpp
+@@ -1288,6 +1288,13 @@ Value *SCEVExpander::expandAddRecExprLiterally(const SCEVAddRecExpr *S) {
+ if (!SE.dominates(Step, L->getHeader())) {
+ PostLoopScale = Step;
+ Step = SE.getConstant(Normalized->getType(), 1);
++ if (!Start->isZero()) {
++ // The normalization below assumes that Start is constant zero, so if
++ // it isn't re-associate Start to PostLoopOffset.
++ assert(!PostLoopOffset && "Start not-null but PostLoopOffset set?");
++ PostLoopOffset = Start;
++ Start = SE.getConstant(Normalized->getType(), 0);
++ }
+ Normalized =
+ cast<SCEVAddRecExpr>(SE.getAddRecExpr(
+ Start, Step, Normalized->getLoop(),
+diff --git a/test/Analysis/ScalarEvolution/incorrect-offset-scaling.ll b/test/Analysis/ScalarEvolution/incorrect-offset-scaling.ll
+new file mode 100644
+index 0000000..7ffb093
+--- /dev/null
++++ b/test/Analysis/ScalarEvolution/incorrect-offset-scaling.ll
+@@ -0,0 +1,48 @@
++; RUN: opt -S -loop-reduce < %s | FileCheck %s
++
++target triple = "x86_64-unknown-unknown"
++target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
++
++define void @incorrect_offset_scaling(i64, i64*) {
++top:
++ br label %L
++
++L: ; preds = %idxend.10, %idxend, %L2, %top
++ br i1 undef, label %L, label %L1
++
++L1: ; preds = %L1.preheader, %L2
++ %r13 = phi i64 [ %r1, %L2 ], [ 1, %L ]
++; CHECK: %lsr.iv = phi i64 [ 0, %L{{[^ ]+}} ], [ %lsr.iv.next, %L2 ]
++; CHECK-NOT: %lsr.iv = phi i64 [ -1, %L{{[^ ]+}} ], [ %lsr.iv.next, %L2 ]
++; CHECK: br
++ %r0 = add i64 %r13, -1
++ br label %idxend.8
++
++L2: ; preds = %idxend.8
++ %r1 = add i64 %r13, 1
++ br i1 undef, label %L, label %L1
++
++if6: ; preds = %idxend.8
++ %r2 = add i64 %0, -1
++ %r3 = load i64, i64* %1, align 8
++; CHECK-NOT: %r2
++; CHECK: %r3 = load i64
++ br label %ib
++
++idxend.8: ; preds = %L1
++ br i1 undef, label %if6, label %L2
++
++ib: ; preds = %if6
++ %r4 = mul i64 %r3, %r0
++ %r5 = add i64 %r2, %r4
++ %r6 = icmp ult i64 %r5, undef
++; CHECK %2 = mul i64 %lsr.iv, %r3
++; CHECK %3 = add i64 %1, -1
++; CHECK %4 = add i64 %0, %r3
++; CHECK %r6
++ %r7 = getelementptr i64, i64* undef, i64 %r5
++ store i64 1, i64* %r7, align 8
++; CHECK %5 = mul i64 %lsr.iv, %r3
++; CHECK %6 = add i64 %5, -1
++ br label %L
++}
diff --git a/main/llvm/llvm-0005-optimize-store-of-bitcast-from-vector-to-aggregate.patch b/main/llvm/llvm-0005-optimize-store-of-bitcast-from-vector-to-aggregate.patch
new file mode 100644
index 0000000000..7f891b66db
--- /dev/null
+++ b/main/llvm/llvm-0005-optimize-store-of-bitcast-from-vector-to-aggregate.patch
@@ -0,0 +1,181 @@
+From 1ca1fcaa5b4c75a65a202badfd5df8240a36ca0f Mon Sep 17 00:00:00 2001
+From: "Arch D. Robison" <arch.robison@intel.com>
+Date: Mon, 25 Apr 2016 22:22:39 +0000
+Subject: [PATCH] Optimize store of "bitcast" from vector to aggregate.
+
+This patch is what was the "instcombine" portion of D14185, with an additional
+test added (see julia_pseudovec in test/Transforms/InstCombine/insert-val-extract-elem.ll).
+The patch causes instcombine to replace sequences of extractelement-insertvalue-store
+that act essentially like a bitcast followed by a store.
+
+Differential review: http://reviews.llvm.org/D14260
+
+git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267482 91177308-0d34-0410-b5e6-96231b3b80d8
+
+Alpine maintainer notes:
+ - Updated for llvm 3.8.1.
+ - This patch replaces llvm-D14260.patch from Julia.
+---
+ .../InstCombine/InstCombineLoadStoreAlloca.cpp | 60 ++++++++++++++++++
+ .../InstCombine/insert-val-extract-elem.ll | 74 ++++++++++++++++++++++
+ 2 files changed, 134 insertions(+)
+ create mode 100644 test/Transforms/InstCombine/insert-val-extract-elem.ll
+
+diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+index 96f0908..0ee6045 100644
+--- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
++++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+@@ -913,6 +913,61 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
+ return nullptr;
+ }
+
++/// \brief Look for extractelement/insertvalue sequence that acts like a bitcast.
++///
++/// \returns underlying value that was "cast", or nullptr otherwise.
++///
++/// For example, if we have:
++///
++/// %E0 = extractelement <2 x double> %U, i32 0
++/// %V0 = insertvalue [2 x double] undef, double %E0, 0
++/// %E1 = extractelement <2 x double> %U, i32 1
++/// %V1 = insertvalue [2 x double] %V0, double %E1, 1
++///
++/// and the layout of a <2 x double> is isomorphic to a [2 x double],
++/// then %V1 can be safely approximated by a conceptual "bitcast" of %U.
++/// Note that %U may contain non-undef values where %V1 has undef.
++static Value *likeBitCastFromVector(InstCombiner &IC, Value *V) {
++ Value *U = nullptr;
++ while (auto *IV = dyn_cast<InsertValueInst>(V)) {
++ auto *E = dyn_cast<ExtractElementInst>(IV->getInsertedValueOperand());
++ if (!E)
++ return nullptr;
++ auto *W = E->getVectorOperand();
++ if (!U)
++ U = W;
++ else if (U != W)
++ return nullptr;
++ auto *CI = dyn_cast<ConstantInt>(E->getIndexOperand());
++ if (!CI || IV->getNumIndices() != 1 || CI->getZExtValue() != *IV->idx_begin())
++ return nullptr;
++ V = IV->getAggregateOperand();
++ }
++ if (!isa<UndefValue>(V) ||!U)
++ return nullptr;
++
++ auto *UT = cast<VectorType>(U->getType());
++ auto *VT = V->getType();
++ // Check that types UT and VT are bitwise isomorphic.
++ const auto &DL = IC.getDataLayout();
++ if (DL.getTypeStoreSizeInBits(UT) != DL.getTypeStoreSizeInBits(VT)) {
++ return nullptr;
++ }
++ if (auto *AT = dyn_cast<ArrayType>(VT)) {
++ if (AT->getNumElements() != UT->getNumElements())
++ return nullptr;
++ } else {
++ auto *ST = cast<StructType>(VT);
++ if (ST->getNumElements() != UT->getNumElements())
++ return nullptr;
++ for (const auto *EltT : ST->elements()) {
++ if (EltT != UT->getElementType())
++ return nullptr;
++ }
++ }
++ return U;
++}
++
+ /// \brief Combine stores to match the type of value being stored.
+ ///
+ /// The core idea here is that the memory does not have any intrinsic type and
+@@ -924,6 +979,11 @@
+ return true;
+ }
+
++ if (Value *U = likeBitCastFromVector(IC, V)) {
++ combineStoreToNewValue(IC, SI, U);
++ return true;
++ }
++
+ // FIXME: We should also canonicalize loads of vectors when their elements are
+ // cast to other types.
+ return false;
+diff --git a/test/Transforms/InstCombine/insert-val-extract-elem.ll b/test/Transforms/InstCombine/insert-val-extract-elem.ll
+new file mode 100644
+index 0000000..db7b403
+--- /dev/null
++++ b/test/Transforms/InstCombine/insert-val-extract-elem.ll
+@@ -0,0 +1,74 @@
++; RUN: opt -S -instcombine %s | FileCheck %s
++
++; CHECK-LABEL: julia_2xdouble
++; CHECK-NOT: insertvalue
++; CHECK-NOT: extractelement
++; CHECK: store <2 x double>
++define void @julia_2xdouble([2 x double]* sret, <2 x double>*) {
++top:
++ %x = load <2 x double>, <2 x double>* %1
++ %x0 = extractelement <2 x double> %x, i32 0
++ %i0 = insertvalue [2 x double] undef, double %x0, 0
++ %x1 = extractelement <2 x double> %x, i32 1
++ %i1 = insertvalue [2 x double] %i0, double %x1, 1
++ store [2 x double] %i1, [2 x double]* %0, align 4
++ ret void
++}
++
++; Test with two inserts to the same index
++; CHECK-LABEL: julia_2xi64
++; CHECK-NOT: insertvalue
++; CHECK-NOT: extractelement
++; CHECK: store <2 x i64>
++define void @julia_2xi64([2 x i64]* sret, <2 x i64>*) {
++top:
++ %x = load <2 x i64>, <2 x i64>* %1
++ %x0 = extractelement <2 x i64> %x, i32 1
++ %i0 = insertvalue [2 x i64] undef, i64 %x0, 0
++ %x1 = extractelement <2 x i64> %x, i32 1
++ %i1 = insertvalue [2 x i64] %i0, i64 %x1, 1
++ %x2 = extractelement <2 x i64> %x, i32 0
++ %i2 = insertvalue [2 x i64] %i1, i64 %x2, 0
++ store [2 x i64] %i2, [2 x i64]* %0, align 4
++ ret void
++}
++
++; CHECK-LABEL: julia_4xfloat
++; CHECK-NOT: insertvalue
++; CHECK-NOT: extractelement
++; CHECK: store <4 x float>
++define void @julia_4xfloat([4 x float]* sret, <4 x float>*) {
++top:
++ %x = load <4 x float>, <4 x float>* %1
++ %x0 = extractelement <4 x float> %x, i32 0
++ %i0 = insertvalue [4 x float] undef, float %x0, 0
++ %x1 = extractelement <4 x float> %x, i32 1
++ %i1 = insertvalue [4 x float] %i0, float %x1, 1
++ %x2 = extractelement <4 x float> %x, i32 2
++ %i2 = insertvalue [4 x float] %i1, float %x2, 2
++ %x3 = extractelement <4 x float> %x, i32 3
++ %i3 = insertvalue [4 x float] %i2, float %x3, 3
++ store [4 x float] %i3, [4 x float]* %0, align 4
++ ret void
++}
++
++%pseudovec = type { float, float, float, float }
++
++; CHECK-LABEL: julia_pseudovec
++; CHECK-NOT: insertvalue
++; CHECK-NOT: extractelement
++; CHECK: store <4 x float>
++define void @julia_pseudovec(%pseudovec* sret, <4 x float>*) {
++top:
++ %x = load <4 x float>, <4 x float>* %1
++ %x0 = extractelement <4 x float> %x, i32 0
++ %i0 = insertvalue %pseudovec undef, float %x0, 0
++ %x1 = extractelement <4 x float> %x, i32 1
++ %i1 = insertvalue %pseudovec %i0, float %x1, 1
++ %x2 = extractelement <4 x float> %x, i32 2
++ %i2 = insertvalue %pseudovec %i1, float %x2, 2
++ %x3 = extractelement <4 x float> %x, i32 3
++ %i3 = insertvalue %pseudovec %i2, float %x3, 3
++ store %pseudovec %i3, %pseudovec* %0, align 4
++ ret void
++}
diff --git a/main/llvm/llvm-0006-clone-every-functions-debug-info.patch b/main/llvm/llvm-0006-clone-every-functions-debug-info.patch
new file mode 100644
index 0000000000..567ddcadd4
--- /dev/null
+++ b/main/llvm/llvm-0006-clone-every-functions-debug-info.patch
@@ -0,0 +1,129 @@
+From 11adcc4de0797c83e61ae0240927f0bafcf041a9 Mon Sep 17 00:00:00 2001
+From: Keno Fischer <kfischer@college.harvard.edu>
+Date: Sat, 13 Feb 2016 02:04:29 +0000
+Subject: [PATCH] [Cloning] Clone every Function's Debug Info
+
+Summary:
+Export the CloneDebugInfoMetadata utility, which clones all debug info
+associated with a function into the first module. Also use this function
+in CloneModule on each function we clone (the CloneFunction entrypoint
+already does this).
+
+Without this, cloning a module will lead to DI quality regressions,
+especially since r252219 reversed the Function <-> DISubprogram edge
+(before we could get lucky and have this edge preserved if the
+DISubprogram itself was, e.g. due to location metadata).
+
+This was verified to fix missing debug information in julia and
+a unittest to verify the new behavior is included.
+
+Patch by Yichao Yu! Thanks!
+
+Reviewers: loladiro, pcc
+Differential Revision: http://reviews.llvm.org/D17165
+
+git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260791 91177308-0d34-0410-b5e6-96231b3b80d8
+
+Alpine maintainer notes:
+ - Corresponds to llvm-D17165-D18583.patch in Julia.
+---
+ include/llvm/Transforms/Utils/Cloning.h | 5 +++++
+ lib/Transforms/Utils/CloneFunction.cpp | 4 ++--
+ lib/Transforms/Utils/CloneModule.cpp | 1 +
+ unittests/Transforms/Utils/Cloning.cpp | 25 +++++++++++++++++++++++++
+ 4 files changed, 33 insertions(+), 2 deletions(-)
+
+diff --git a/include/llvm/Transforms/Utils/Cloning.h b/include/llvm/Transforms/Utils/Cloning.h
+index 4f006f2..0bae2bd 100644
+--- a/include/llvm/Transforms/Utils/Cloning.h
++++ b/include/llvm/Transforms/Utils/Cloning.h
+@@ -130,6 +130,11 @@ Function *CloneFunction(const Function *F, ValueToValueMapTy &VMap,
+ bool ModuleLevelChanges,
+ ClonedCodeInfo *CodeInfo = nullptr);
+
++/// Clone the module-level debug info associated with OldFunc. The cloned data
++/// will point to NewFunc instead.
++void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
++ ValueToValueMapTy &VMap);
++
+ /// Clone OldFunc into NewFunc, transforming the old arguments into references
+ /// to VMap values. Note that if NewFunc already has basic blocks, the ones
+ /// cloned into it will be added to the end of the function. This function
+diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp
+index 6454afb..8b5692a 100644
+--- a/lib/Transforms/Utils/CloneFunction.cpp
++++ b/lib/Transforms/Utils/CloneFunction.cpp
+@@ -187,8 +187,8 @@ static void AddOperand(DICompileUnit *CU, DISubprogramArray SPs,
+
+ // Clone the module-level debug info associated with OldFunc. The cloned data
+ // will point to NewFunc instead.
+-static void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
+- ValueToValueMapTy &VMap) {
++void llvm::CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
++ ValueToValueMapTy &VMap) {
+ DebugInfoFinder Finder;
+ Finder.processModule(*OldFunc->getParent());
+
+diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp
+index 53de62a..b16a02a 100644
+--- a/lib/Transforms/Utils/CloneModule.cpp
++++ b/lib/Transforms/Utils/CloneModule.cpp
+@@ -136,6 +136,7 @@ std::unique_ptr<Module> llvm::CloneModule(
+ VMap[&*J] = &*DestI++;
+ }
+
++ CloneDebugInfoMetadata(F, &*I, VMap);
+ SmallVector<ReturnInst*, 8> Returns; // Ignore returns cloned.
+ CloneFunctionInto(F, &*I, VMap, /*ModuleLevelChanges=*/true, Returns);
+ }
+diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp
+index 25e322e..b761e4e 100644
+--- a/unittests/Transforms/Utils/Cloning.cpp
++++ b/unittests/Transforms/Utils/Cloning.cpp
+@@ -423,6 +423,7 @@ class CloneModule : public ::testing::Test {
+ void SetupModule() { OldM = new Module("", C); }
+
+ void CreateOldModule() {
++ DIBuilder DBuilder(*OldM);
+ IRBuilder<> IBuilder(C);
+
+ auto *FuncType = FunctionType::get(Type::getVoidTy(C), false);
+@@ -431,9 +432,25 @@ class CloneModule : public ::testing::Test {
+ auto *F =
+ Function::Create(FuncType, GlobalValue::PrivateLinkage, "f", OldM);
+ F->setPersonalityFn(PersFn);
++
++ // Create debug info
++ auto *File = DBuilder.createFile("filename.c", "/file/dir/");
++ DITypeRefArray ParamTypes = DBuilder.getOrCreateTypeArray(None);
++ DISubroutineType *DFuncType = DBuilder.createSubroutineType(ParamTypes);
++ auto *CU =
++ DBuilder.createCompileUnit(dwarf::DW_LANG_C99, "filename.c",
++ "/file/dir", "CloneModule", false, "", 0);
++ // Function DI
++ auto *Subprogram = DBuilder.createFunction(CU, "f", "f", File, 4, DFuncType,
++ true, true, 3, 0, false);
++ F->setSubprogram(Subprogram);
++
+ auto *Entry = BasicBlock::Create(C, "", F);
+ IBuilder.SetInsertPoint(Entry);
+ IBuilder.CreateRetVoid();
++
++ // Finalize the debug info
++ DBuilder.finalize();
+ }
+
+ void CreateNewModule() { NewM = llvm::CloneModule(OldM).release(); }
+@@ -447,4 +464,12 @@ TEST_F(CloneModule, Verify) {
+ EXPECT_FALSE(verifyModule(*NewM));
+ }
+
++TEST_F(CloneModule, Subprogram) {
++ Function *NewF = NewM->getFunction("f");
++ DISubprogram *SP = NewF->getSubprogram();
++ EXPECT_TRUE(SP != nullptr);
++ EXPECT_EQ(SP->getName(), "f");
++ EXPECT_EQ(SP->getFile()->getFilename(), "filename.c");
++ EXPECT_EQ(SP->getLine(), (unsigned)4);
++}
+ }
diff --git a/main/llvm/llvm-0007-reduce-complexity-of-debug-info-clonning-and-fix-correctness.patch b/main/llvm/llvm-0007-reduce-complexity-of-debug-info-clonning-and-fix-correctness.patch
new file mode 100644
index 0000000000..0930c28e8f
--- /dev/null
+++ b/main/llvm/llvm-0007-reduce-complexity-of-debug-info-clonning-and-fix-correctness.patch
@@ -0,0 +1,102 @@
+From af289e04413504c3bdc252e08c3fe17bf7ea6dc8 Mon Sep 17 00:00:00 2001
+From: Peter Collingbourne <peter@pcc.me.uk>
+Date: Wed, 30 Mar 2016 22:05:13 +0000
+Subject: [PATCH] Cloning: Reduce complexity of debug info cloning and fix
+ correctness issue.
+
+Commit r260791 contained an error in that it would introduce a cross-module
+reference in the old module. It also introduced O(N^2) complexity in the
+module cloner by requiring the entire module to be visited for each function.
+Fix both of these problems by avoiding use of the CloneDebugInfoMetadata
+function (which is only designed to do intra-module cloning) and cloning
+function-attached metadata in the same way that we clone all other metadata.
+
+Differential Revision: http://reviews.llvm.org/D18583
+
+git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264935 91177308-0d34-0410-b5e6-96231b3b80d8
+
+Alpine maintainer notes:
+ - Corresponds to llvm-D17165-D18583.patch in Julia.
+---
+ include/llvm/Transforms/Utils/Cloning.h | 5 -----
+ lib/Transforms/Utils/CloneFunction.cpp | 13 +++++++++++--
+ lib/Transforms/Utils/CloneModule.cpp | 1 -
+ unittests/Transforms/Utils/Cloning.cpp | 6 ++++++
+ 4 files changed, 17 insertions(+), 8 deletions(-)
+
+diff --git a/include/llvm/Transforms/Utils/Cloning.h b/include/llvm/Transforms/Utils/Cloning.h
+index 0bae2bd..4f006f2 100644
+--- a/include/llvm/Transforms/Utils/Cloning.h
++++ b/include/llvm/Transforms/Utils/Cloning.h
+@@ -130,11 +130,6 @@ Function *CloneFunction(const Function *F, ValueToValueMapTy &VMap,
+ bool ModuleLevelChanges,
+ ClonedCodeInfo *CodeInfo = nullptr);
+
+-/// Clone the module-level debug info associated with OldFunc. The cloned data
+-/// will point to NewFunc instead.
+-void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
+- ValueToValueMapTy &VMap);
+-
+ /// Clone OldFunc into NewFunc, transforming the old arguments into references
+ /// to VMap values. Note that if NewFunc already has basic blocks, the ones
+ /// cloned into it will be added to the end of the function. This function
+diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp
+index 05b0a17..8e1715a 100644
+--- a/lib/Transforms/Utils/CloneFunction.cpp
++++ b/lib/Transforms/Utils/CloneFunction.cpp
+@@ -119,6 +119,15 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
+ .addAttributes(NewFunc->getContext(), AttributeSet::FunctionIndex,
+ OldAttrs.getFnAttributes()));
+
++ SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
++ OldFunc->getAllMetadata(MDs);
++ for (auto MD : MDs)
++ NewFunc->setMetadata(
++ MD.first,
++ MapMetadata(MD.second, VMap,
++ ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
++ TypeMapper, Materializer));
++
+ // Loop over all of the basic blocks in the function, cloning them as
+ // appropriate. Note that we save BE this way in order to handle cloning of
+ // recursive functions into themselves.
+@@ -187,8 +196,8 @@ static void AddOperand(DICompileUnit *CU, DISubprogramArray SPs,
+
+ // Clone the module-level debug info associated with OldFunc. The cloned data
+ // will point to NewFunc instead.
+-void llvm::CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
+- ValueToValueMapTy &VMap) {
++static void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
++ ValueToValueMapTy &VMap) {
+ DebugInfoFinder Finder;
+ Finder.processModule(*OldFunc->getParent());
+
+diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp
+index 494e275..929f51b 100644
+--- a/lib/Transforms/Utils/CloneModule.cpp
++++ b/lib/Transforms/Utils/CloneModule.cpp
+@@ -138,7 +138,6 @@ std::unique_ptr<Module> llvm::CloneModule(
+ VMap[&*J] = &*DestI++;
+ }
+
+- CloneDebugInfoMetadata(F, &*I, VMap);
+ SmallVector<ReturnInst*, 8> Returns; // Ignore returns cloned.
+ CloneFunctionInto(F, &*I, VMap, /*ModuleLevelChanges=*/true, Returns);
+ }
+diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp
+index b761e4e..f06a20f 100644
+--- a/unittests/Transforms/Utils/Cloning.cpp
++++ b/unittests/Transforms/Utils/Cloning.cpp
+@@ -464,6 +464,12 @@ TEST_F(CloneModule, Verify) {
+ EXPECT_FALSE(verifyModule(*NewM));
+ }
+
++TEST_F(CloneModule, OldModuleUnchanged) {
++ DebugInfoFinder Finder;
++ Finder.processModule(*OldM);
++ EXPECT_EQ(1U, Finder.subprogram_count());
++}
++
+ TEST_F(CloneModule, Subprogram) {
+ Function *NewF = NewM->getFunction("f");
+ DISubprogram *SP = NewF->getSubprogram();
diff --git a/main/llvm/llvm-0008-dont-widen-metadata-on-store-to-load-forwarding.patch b/main/llvm/llvm-0008-dont-widen-metadata-on-store-to-load-forwarding.patch
new file mode 100644
index 0000000000..b66584dc9a
--- /dev/null
+++ b/main/llvm/llvm-0008-dont-widen-metadata-on-store-to-load-forwarding.patch
@@ -0,0 +1,107 @@
+From 3c80c2658022201214241e9229ac35097cc476d2 Mon Sep 17 00:00:00 2001
+From: Eli Friedman <eli.friedman@gmail.com>
+Date: Thu, 16 Jun 2016 02:33:42 +0000
+Subject: [PATCH] [InstCombine] Don't widen metadata on store-to-load
+ forwarding
+
+The original check for load CSE or store-to-load forwarding is wrong
+when the forwarded stored value happened to be a load.
+
+Ref https://github.com/JuliaLang/julia/issues/16894
+
+Differential Revision: http://reviews.llvm.org/D21271
+
+Patch by Yichao Yu!
+
+git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272868 91177308-0d34-0410-b5e6-96231b3b80d8
+
+Alpine maintainer notes:
+ - Updated for llvm 3.8.1.
+ - Corresponds to llvm-D21271-instcombine-tbaa-3.8.patch in Julia.
+---
+ include/llvm/Analysis/Loads.h | 3 ++-
+ lib/Analysis/Loads.cpp | 5 ++++-
+ .../InstCombine/InstCombineLoadStoreAlloca.cpp | 6 ++++--
+ test/Transforms/InstCombine/tbaa-store-to-load.ll | 17 +++++++++++++++++
+ 4 files changed, 27 insertions(+), 4 deletions(-)
+ create mode 100644 test/Transforms/InstCombine/tbaa-store-to-load.ll
+
+diff --git a/include/llvm/Analysis/Loads.h b/include/llvm/Analysis/Loads.h
+index e5bd0c8..9d24b7b 100644
+--- a/include/llvm/Analysis/Loads.h
++++ b/include/llvm/Analysis/Loads.h
+@@ -82,7 +82,8 @@ Value *FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB,
+ BasicBlock::iterator &ScanFrom,
+ unsigned MaxInstsToScan = DefMaxInstsToScan,
+ AliasAnalysis *AA = nullptr,
+- AAMDNodes *AATags = nullptr);
++ AAMDNodes *AATags = nullptr,
++ bool *IsLoadCSE = nullptr);
+
+ }
+
+diff --git a/lib/Analysis/Loads.cpp b/lib/Analysis/Loads.cpp
+index dce243c..7d3fd59 100644
+--- a/lib/Analysis/Loads.cpp
++++ b/lib/Analysis/Loads.cpp
+@@ -322,7 +322,8 @@ llvm::DefMaxInstsToScan("available-load-scan-limit", cl::init(6), cl::Hidden,
+ Value *llvm::FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB,
+ BasicBlock::iterator &ScanFrom,
+ unsigned MaxInstsToScan,
+- AliasAnalysis *AA, AAMDNodes *AATags) {
++ AliasAnalysis *AA, AAMDNodes *AATags,
++ bool *IsLoadCSE) {
+ if (MaxInstsToScan == 0)
+ MaxInstsToScan = ~0U;
+
+@@ -374,6 +375,8 @@ Value *llvm::FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB,
+
+ if (AATags)
+ LI->getAAMetadata(*AATags);
++ if (IsLoadCSE)
++ *IsLoadCSE = true;
+ return LI;
+ }
+
+diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+index 6a5d5a6..d312983 100644
+--- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
++++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+@@ -800,10 +800,12 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
+ // separated by a few arithmetic operations.
+ BasicBlock::iterator BBI(LI);
+ AAMDNodes AATags;
++ bool IsLoadCSE = false;
+ if (Value *AvailableVal =
+ FindAvailableLoadedValue(Op, LI.getParent(), BBI,
+- DefMaxInstsToScan, AA, &AATags)) {
+- if (LoadInst *NLI = dyn_cast<LoadInst>(AvailableVal)) {
++ DefMaxInstsToScan, AA, &AATags, &IsLoadCSE)) {
++ if (IsLoadCSE) {
++ LoadInst *NLI = cast<LoadInst>(AvailableVal);
+ unsigned KnownIDs[] = {
+ LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope,
+ LLVMContext::MD_noalias, LLVMContext::MD_range,
+diff --git a/test/Transforms/InstCombine/tbaa-store-to-load.ll b/test/Transforms/InstCombine/tbaa-store-to-load.ll
+new file mode 100644
+index 0000000..707be73
+--- /dev/null
++++ b/test/Transforms/InstCombine/tbaa-store-to-load.ll
+@@ -0,0 +1,17 @@
++; RUN: opt -S -instcombine < %s 2>&1 | FileCheck %s
++
++define i64 @f(i64* %p1, i64* %p2) {
++top:
++ ; check that the tbaa is preserved
++ ; CHECK-LABEL: @f(
++ ; CHECK: %v1 = load i64, i64* %p1, align 8, !tbaa !0
++ ; CHECK: store i64 %v1, i64* %p2, align 8
++ ; CHECK: ret i64 %v1
++ %v1 = load i64, i64* %p1, align 8, !tbaa !0
++ store i64 %v1, i64* %p2, align 8
++ %v2 = load i64, i64* %p2, align 8
++ ret i64 %v2
++}
++
++!0 = !{!1, !1, i64 0}
++!1 = !{!"load_tbaa"}