Blame patches/llvm_host/llvm-0008-dont-widen-metadata-on-store-to-load-forwarding.patch

Lucio Andrés Illanes Albornoz (arab, vxp) 585426
From 3c80c2658022201214241e9229ac35097cc476d2 Mon Sep 17 00:00:00 2001
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
From: Eli Friedman <eli.friedman@gmail.com>
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Date: Thu, 16 Jun 2016 02:33:42 +0000
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Subject: [PATCH] [InstCombine] Don't widen metadata on store-to-load
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 forwarding
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
The original check for load CSE or store-to-load forwarding is wrong
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
when the forwarded stored value happened to be a load.
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Ref https://github.com/JuliaLang/julia/issues/16894
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Differential Revision: http://reviews.llvm.org/D21271
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Patch by Yichao Yu!
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@272868 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
  - Updated for llvm 3.8.1.
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
  - Corresponds to llvm-D21271-instcombine-tbaa-3.8.patch in Julia.
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
---
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 include/llvm/Analysis/Loads.h                           |  3 ++-
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 lib/Analysis/Loads.cpp                                  |  5 ++++-
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 .../InstCombine/InstCombineLoadStoreAlloca.cpp          |  6 ++++--
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 test/Transforms/InstCombine/tbaa-store-to-load.ll       | 17 +++++++++++++++++
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 4 files changed, 27 insertions(+), 4 deletions(-)
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 create mode 100644 test/Transforms/InstCombine/tbaa-store-to-load.ll
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
diff --git a/include/llvm/Analysis/Loads.h b/include/llvm/Analysis/Loads.h
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
index e5bd0c8..9d24b7b 100644
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
--- a/include/llvm/Analysis/Loads.h
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+++ b/include/llvm/Analysis/Loads.h
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
@@ -82,7 +82,8 @@ Value *FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
                                 BasicBlock::iterator &ScanFrom,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
                                 unsigned MaxInstsToScan = DefMaxInstsToScan,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
                                 AliasAnalysis *AA = nullptr,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
-                                AAMDNodes *AATags = nullptr);
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+                                AAMDNodes *AATags = nullptr,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+                                bool *IsLoadCSE = nullptr);
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 }
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
diff --git a/lib/Analysis/Loads.cpp b/lib/Analysis/Loads.cpp
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
index dce243c..7d3fd59 100644
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
--- a/lib/Analysis/Loads.cpp
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+++ b/lib/Analysis/Loads.cpp
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
@@ -322,7 +322,8 @@ llvm::DefMaxInstsToScan("available-load-scan-limit", cl::init(6), cl::Hidden,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 Value *llvm::FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
                                       BasicBlock::iterator &ScanFrom,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
                                       unsigned MaxInstsToScan,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
-                                      AliasAnalysis *AA, AAMDNodes *AATags) {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+                                      AliasAnalysis *AA, AAMDNodes *AATags,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+                                      bool *IsLoadCSE) {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
   if (MaxInstsToScan == 0)
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
     MaxInstsToScan = ~0U;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
@@ -374,6 +375,8 @@ Value *llvm::FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
         if (AATags)
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
           LI->getAAMetadata(*AATags);
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+        if (IsLoadCSE)
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+            *IsLoadCSE = true;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
         return LI;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
       }
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
 
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
index 6a5d5a6..d312983 100644
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
--- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
@@ -800,10 +800,12 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
   // separated by a few arithmetic operations.
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
   BasicBlock::iterator BBI(LI);
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
   AAMDNodes AATags;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  bool IsLoadCSE = false;
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
   if (Value *AvailableVal =
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
       FindAvailableLoadedValue(Op, LI.getParent(), BBI,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
-                               DefMaxInstsToScan, AA, &AATags)) {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
-    if (LoadInst *NLI = dyn_cast<LoadInst>(AvailableVal)) {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+                               DefMaxInstsToScan, AA, &AATags, &IsLoadCSE)) {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+    if (IsLoadCSE) {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+      LoadInst *NLI = cast<LoadInst>(AvailableVal);
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
       unsigned KnownIDs[] = {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
           LLVMContext::MD_tbaa,            LLVMContext::MD_alias_scope,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
           LLVMContext::MD_noalias, LLVMContext::MD_range,
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
diff --git a/test/Transforms/InstCombine/tbaa-store-to-load.ll b/test/Transforms/InstCombine/tbaa-store-to-load.ll
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
new file mode 100644
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
index 0000000..707be73
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
--- /dev/null
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+++ b/test/Transforms/InstCombine/tbaa-store-to-load.ll
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
@@ -0,0 +1,17 @@
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+; RUN: opt -S -instcombine < %s 2>&1 | FileCheck %s
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+define i64 @f(i64* %p1, i64* %p2) {
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+top:
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  ; check that the tbaa is preserved
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  ; CHECK-LABEL: @f(
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  ; CHECK: %v1 = load i64, i64* %p1, align 8, !tbaa !0
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  ; CHECK: store i64 %v1, i64* %p2, align 8
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  ; CHECK: ret i64 %v1
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  %v1 = load i64, i64* %p1, align 8, !tbaa !0
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  store i64 %v1, i64* %p2, align 8
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  %v2 = load i64, i64* %p2, align 8
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+  ret i64 %v2
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+}
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+!0 = !{!1, !1, i64 0}
Lucio Andrés Illanes Albornoz (arab, vxp) 585426
+!1 = !{!"load_tbaa"}