[patches] Cherry pick CLS for: upstream reverts

c89cfbd4ddf Revert "[DAG] Extend SearchForAndLoads with any_extend handling"
b6e048c6e51 Test fixes for prior patch
d7dd7ad827a Revert "[ASan] Not linking asan_static library for DSO."
f69f23396d3 Revert "DebugInfo: Don't put types in type units if they reference internal linkage types"

Test: N/A
Bug: http://b/219872355
Change-Id: Ifa0f0f924ac5a80deface855e1bcb20b4ae87e55
diff --git a/patches/PATCHES.json b/patches/PATCHES.json
index 046daca..55e41dc 100644
--- a/patches/PATCHES.json
+++ b/patches/PATCHES.json
@@ -487,6 +487,62 @@
     {
         "metadata": {
             "info": [],
+            "title": "[UPSTREAM] Revert \"[DAG] Extend SearchForAndLoads with any_extend handling\""
+        },
+        "platforms": [
+            "android"
+        ],
+        "rel_patch_path": "cherry/c89cfbd4ddfa4e01fea1eb87aba9cdcd0e31d3a8.patch",
+        "version_range": {
+            "from": 450784,
+            "until": 451241
+        }
+    },
+    {
+        "metadata": {
+            "info": [],
+            "title": "[UPSTREAM] Revert \"[ASan] Not linking asan_static library for DSO.\""
+        },
+        "platforms": [
+            "android"
+        ],
+        "rel_patch_path": "cherry/d7dd7ad827a0a78314f3c9b55f4778a6059840f3.patch",
+        "version_range": {
+            "from": 450784,
+            "until": 451265
+        }
+    },
+    {
+        "metadata": {
+            "info": [],
+            "title": "[UPSTREAM] Revert \"DebugInfo: Don't put types in type units if they reference internal linkage types\""
+        },
+        "platforms": [
+            "android"
+        ],
+        "rel_patch_path": "cherry/f69f23396d32c95dacf3765bc63af02b23ccff3e.patch",
+        "version_range": {
+            "from": 450784,
+            "until": 451266
+        }
+    },
+    {
+        "metadata": {
+            "info": [],
+            "title": "[UPSTREAM] Test fixes for prior patch"
+        },
+        "platforms": [
+            "android"
+        ],
+        "rel_patch_path": "cherry/b6e048c6e516df5abc4be323349b5f7d15c08ede.patch",
+        "version_range": {
+            "from": 450784,
+            "until": 451267
+        }
+    },
+    {
+        "metadata": {
+            "info": [],
             "title": "[UPSTREAM] Revert \"[Clang] Propagate guaranteed alignment for malloc and others\""
         },
         "platforms": [
diff --git a/patches/cherry/b6e048c6e516df5abc4be323349b5f7d15c08ede.patch b/patches/cherry/b6e048c6e516df5abc4be323349b5f7d15c08ede.patch
new file mode 100644
index 0000000..3d89a4f
--- /dev/null
+++ b/patches/cherry/b6e048c6e516df5abc4be323349b5f7d15c08ede.patch
@@ -0,0 +1,103 @@
+From b6e048c6e516df5abc4be323349b5f7d15c08ede Mon Sep 17 00:00:00 2001
+From: David Blaikie <dblaikie@gmail.com>
+Date: Tue, 1 Feb 2022 16:15:25 -0800
+Subject: [PATCH] Test fixes for prior patch
+
+---
+ llvm/test/DebugInfo/X86/tu-to-non-tu.ll | 61 +++++++++++++++++--------
+ 1 file changed, 42 insertions(+), 19 deletions(-)
+
+diff --git a/llvm/test/DebugInfo/X86/tu-to-non-tu.ll b/llvm/test/DebugInfo/X86/tu-to-non-tu.ll
+index 4b8ea04bedc5..6702b330a1dc 100644
+--- a/llvm/test/DebugInfo/X86/tu-to-non-tu.ll
++++ b/llvm/test/DebugInfo/X86/tu-to-non-tu.ll
+@@ -1,17 +1,41 @@
+ ; RUN: llc -filetype=obj -O0 -generate-type-units -mtriple=x86_64-unknown-linux-gnu < %s \
+ ; RUN:     | llvm-dwarfdump -debug-info -debug-types - | FileCheck %s
+ 
+-; Test that a type unit referencing a non-type unit (in this case, it's
+-; bordering on an ODR violation - a type with linkage references a type without
+-; linkage, so there's no way for the first type to be defined in more than one
+-; translation unit, so there's no need for it to be in a type unit - but this
+-; is quirky/rare and an easy way to test a broader issue). The type unit should
+-; not end up with a whole definition of the referenced type - instead it should
+-; have a declaration of the type, while the definition remains in the primary
+-; CU.
+-; (again, arguably in this instance - since the type is only referenced once, it
+-; could go in the TU only - but that requires tracking usage & then deciding
+-; where to put types, which isn't worthwhile right now)
++; Test that a type unit referencing a non-type unit produces a declaration of
++; the referent in the referee.
++
++; This test was intended to test this:
++
++; * Also check that an attempt to reference an internal linkage (defined in an anonymous
++; * namespace) type from a type unit (could happen with a pimpl idiom, for instance -
++; * it does mean the linkage-having type can only be defined in one translation
++; * unit anyway) forces the referent to not be placed in a type unit (because the
++; * declaration of the internal linkage type would be ambiguous/wouldn't allow a
++; * consumer to find the definition with certainty)
++
++; But the implementation was buggy, so for now, it's reverted but still test covered.
++; A buggy input/case looks like this:
++;  namespace {
++;  template <typename> struct a {};
++;  } // namespace
++;  class c {
++;    c();
++;  };
++;  class b {
++;    b();
++;    a<c> ax;
++;  };
++;  b::b() {}
++;  c::c() {}
++
++; I haven't bothered adding a test case for this ^ to avoid regression, as
++; likely we'll move in a different direction entirely, since this approach is
++; incomplete anyway. Specifically it looks like we want a flag on DICompositeType
++; to indicate whether it should go in a type unit - the current frontend strategy
++; of omitting the 'identifier' field is inadequate (since it breaks LLVM IR linking
++; type resolution - leaving a separate decl/def of the same type), so if we fix that
++; we can fix the internal-referencing issue by using such a flag instead of trying
++; to figure it out in the backend.
+ 
+ ; Built from the following source, compiled with this command:
+ ; $ clang++-tot decl.cpp -g -fdebug-types-section -c
+@@ -83,6 +107,13 @@
+ ; CHECK-NOT: DW_TAG
+ ; CHECK: DW_AT_name {{.*}}"tu_ref_non_tu"
+ 
++; CHECK-LABEL: Type Unit:
++; CHECK: DW_TAG_structure_type
++; CHECK-NOT: DW_TAG
++; CHECK: DW_AT_name {{.*}}"ref_internal"
++; CHECK-NOT: DW_TAG
++; CHECK: DW_AT_byte_size
++
+ ; CHECK-LABEL: Type Unit:
+ ; CHECK: DW_TAG_structure_type
+ ; CHECK-NOT: DW_TAG
+@@ -120,19 +151,11 @@
+ ; CHECK-NEXT:   DW_AT_declaration       (true)
+ ; CHECK-NEXT:   DW_AT_signature (0xb1cde890d320f5c2)
+ 
+-; CHECK: DW_TAG_namespace
+-; CHECK-NOT: {{DW_AT_name|DW_TAG}}
+ ; CHECK: DW_TAG_structure_type
+ ; CHECK-NOT: DW_TAG
+ ; CHECK: DW_AT_name {{.*}}"non_tu"
+ 
+ 
+-; CHECK: DW_TAG_structure_type
+-; CHECK-NOT: DW_TAG
+-; CHECK: DW_AT_name {{.*}}"ref_internal"
+-; CHECK-NOT: DW_TAG
+-; CHECK: DW_AT_byte_size
+-
+ ; CHECK: DW_TAG_namespace
+ ; CHECK-NOT: {{DW_TAG|DW_AT}}
+ ; CHECK: DW_TAG_structure_type
+-- 
+2.35.1.723.g4982287a31-goog
+
diff --git a/patches/cherry/c89cfbd4ddfa4e01fea1eb87aba9cdcd0e31d3a8.patch b/patches/cherry/c89cfbd4ddfa4e01fea1eb87aba9cdcd0e31d3a8.patch
new file mode 100644
index 0000000..6784ce5
--- /dev/null
+++ b/patches/cherry/c89cfbd4ddfa4e01fea1eb87aba9cdcd0e31d3a8.patch
@@ -0,0 +1,376 @@
+From c89cfbd4ddfa4e01fea1eb87aba9cdcd0e31d3a8 Mon Sep 17 00:00:00 2001
+From: David Green <david.green@arm.com>
+Date: Tue, 1 Feb 2022 20:18:40 +0000
+Subject: [PATCH] Revert "[DAG] Extend SearchForAndLoads with any_extend
+ handling"
+
+This reverts commit 100763a88fe97b22cd5e3f69d203669aac3ed48f as it was
+making incorrect assumptions about implicit zero_extends.
+---
+ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp |  41 ++----
+ .../CodeGen/AArch64/combine-andintoload.ll    | 120 ++++++++++--------
+ llvm/test/CodeGen/X86/pr35763.ll              |   8 +-
+ 3 files changed, 84 insertions(+), 85 deletions(-)
+
+diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+index 0ed2bd9d6d62..041d7e5b4a4a 100644
+--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
++++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+@@ -5531,8 +5531,6 @@ bool DAGCombiner::SearchForAndLoads(SDNode *N,
+ 
+     // Some constants may need fixing up later if they are too large.
+     if (auto *C = dyn_cast<ConstantSDNode>(Op)) {
+-      if (Mask->getValueType(0) != C->getValueType(0))
+-        return false;
+       if ((N->getOpcode() == ISD::OR || N->getOpcode() == ISD::XOR) &&
+           (Mask->getAPIntValue() & C->getAPIntValue()) != C->getAPIntValue())
+         NodesWithConsts.insert(N);
+@@ -5566,9 +5564,9 @@ bool DAGCombiner::SearchForAndLoads(SDNode *N,
+     case ISD::AssertZext: {
+       unsigned ActiveBits = Mask->getAPIntValue().countTrailingOnes();
+       EVT ExtVT = EVT::getIntegerVT(*DAG.getContext(), ActiveBits);
+-      EVT VT = Op.getOpcode() == ISD::AssertZext
+-                   ? cast<VTSDNode>(Op.getOperand(1))->getVT()
+-                   : Op.getOperand(0).getValueType();
++      EVT VT = Op.getOpcode() == ISD::AssertZext ?
++        cast<VTSDNode>(Op.getOperand(1))->getVT() :
++        Op.getOperand(0).getValueType();
+ 
+       // We can accept extending nodes if the mask is wider or an equal
+       // width to the original type.
+@@ -5576,15 +5574,6 @@ bool DAGCombiner::SearchForAndLoads(SDNode *N,
+         continue;
+       break;
+     }
+-    case ISD::ANY_EXTEND: {
+-      unsigned ActiveBits = Mask->getAPIntValue().countTrailingOnes();
+-      EVT ExtVT = EVT::getIntegerVT(*DAG.getContext(), ActiveBits);
+-      EVT VT = Op.getOperand(0).getValueType();
+-      if (ExtVT.bitsGE(VT))
+-        break;
+-      // Fallthrough to searching for nodes from the operands of the extend.
+-      LLVM_FALLTHROUGH;
+-    }
+     case ISD::OR:
+     case ISD::XOR:
+     case ISD::AND:
+@@ -5644,14 +5633,12 @@ bool DAGCombiner::BackwardsPropagateMask(SDNode *N) {
+     // masking.
+     if (FixupNode) {
+       LLVM_DEBUG(dbgs() << "First, need to fix up: "; FixupNode->dump());
+-      SDValue MaskOpT = DAG.getZExtOrTrunc(MaskOp, SDLoc(FixupNode),
+-                                           FixupNode->getValueType(0));
+-      SDValue And =
+-          DAG.getNode(ISD::AND, SDLoc(FixupNode), FixupNode->getValueType(0),
+-                      SDValue(FixupNode, 0), MaskOpT);
++      SDValue And = DAG.getNode(ISD::AND, SDLoc(FixupNode),
++                                FixupNode->getValueType(0),
++                                SDValue(FixupNode, 0), MaskOp);
+       DAG.ReplaceAllUsesOfValueWith(SDValue(FixupNode, 0), And);
+       if (And.getOpcode() == ISD ::AND)
+-        DAG.UpdateNodeOperands(And.getNode(), SDValue(FixupNode, 0), MaskOpT);
++        DAG.UpdateNodeOperands(And.getNode(), SDValue(FixupNode, 0), MaskOp);
+     }
+ 
+     // Narrow any constants that need it.
+@@ -5660,12 +5647,10 @@ bool DAGCombiner::BackwardsPropagateMask(SDNode *N) {
+       SDValue Op1 = LogicN->getOperand(1);
+ 
+       if (isa<ConstantSDNode>(Op0))
+-        std::swap(Op0, Op1);
++          std::swap(Op0, Op1);
+ 
+-      SDValue MaskOpT =
+-          DAG.getZExtOrTrunc(MaskOp, SDLoc(Op1), Op1.getValueType());
+-      SDValue And =
+-          DAG.getNode(ISD::AND, SDLoc(Op1), Op1.getValueType(), Op1, MaskOpT);
++      SDValue And = DAG.getNode(ISD::AND, SDLoc(Op1), Op1.getValueType(),
++                                Op1, MaskOp);
+ 
+       DAG.UpdateNodeOperands(LogicN, Op0, And);
+     }
+@@ -5673,14 +5658,12 @@ bool DAGCombiner::BackwardsPropagateMask(SDNode *N) {
+     // Create narrow loads.
+     for (auto *Load : Loads) {
+       LLVM_DEBUG(dbgs() << "Propagate AND back to: "; Load->dump());
+-      SDValue MaskOpT =
+-          DAG.getZExtOrTrunc(MaskOp, SDLoc(Load), Load->getValueType(0));
+       SDValue And = DAG.getNode(ISD::AND, SDLoc(Load), Load->getValueType(0),
+-                                SDValue(Load, 0), MaskOpT);
++                                SDValue(Load, 0), MaskOp);
+       DAG.ReplaceAllUsesOfValueWith(SDValue(Load, 0), And);
+       if (And.getOpcode() == ISD ::AND)
+         And = SDValue(
+-            DAG.UpdateNodeOperands(And.getNode(), SDValue(Load, 0), MaskOpT), 0);
++            DAG.UpdateNodeOperands(And.getNode(), SDValue(Load, 0), MaskOp), 0);
+       SDValue NewLoad = reduceLoadWidth(And.getNode());
+       assert(NewLoad &&
+              "Shouldn't be masking the load if it can't be narrowed");
+diff --git a/llvm/test/CodeGen/AArch64/combine-andintoload.ll b/llvm/test/CodeGen/AArch64/combine-andintoload.ll
+index d7a69fdd1193..693d318b272a 100644
+--- a/llvm/test/CodeGen/AArch64/combine-andintoload.ll
++++ b/llvm/test/CodeGen/AArch64/combine-andintoload.ll
+@@ -5,14 +5,16 @@
+ define i64 @load32_and16_and(i32* %p, i64 %y) {
+ ; CHECK-LABEL: load32_and16_and:
+ ; CHECK:       // %bb.0:
+-; CHECK-NEXT:    ldrh w8, [x0]
+-; CHECK-NEXT:    and w0, w1, w8
++; CHECK-NEXT:    ldr w8, [x0]
++; CHECK-NEXT:    and w8, w1, w8
++; CHECK-NEXT:    and x0, x8, #0xffff
+ ; CHECK-NEXT:    ret
+ ;
+ ; CHECKBE-LABEL: load32_and16_and:
+ ; CHECKBE:       // %bb.0:
+-; CHECKBE-NEXT:    ldrh w8, [x0, #2]
+-; CHECKBE-NEXT:    and w0, w1, w8
++; CHECKBE-NEXT:    ldr w8, [x0]
++; CHECKBE-NEXT:    and w8, w1, w8
++; CHECKBE-NEXT:    and x0, x8, #0xffff
+ ; CHECKBE-NEXT:    ret
+   %x = load i32, i32* %p, align 4
+   %xz = zext i32 %x to i64
+@@ -24,14 +26,16 @@ define i64 @load32_and16_and(i32* %p, i64 %y) {
+ define i64 @load32_and16_andr(i32* %p, i64 %y) {
+ ; CHECK-LABEL: load32_and16_andr:
+ ; CHECK:       // %bb.0:
+-; CHECK-NEXT:    ldrh w8, [x0]
+-; CHECK-NEXT:    and w0, w1, w8
++; CHECK-NEXT:    ldr w8, [x0]
++; CHECK-NEXT:    and w8, w1, w8
++; CHECK-NEXT:    and x0, x8, #0xffff
+ ; CHECK-NEXT:    ret
+ ;
+ ; CHECKBE-LABEL: load32_and16_andr:
+ ; CHECKBE:       // %bb.0:
+-; CHECKBE-NEXT:    ldrh w8, [x0, #2]
+-; CHECKBE-NEXT:    and w0, w1, w8
++; CHECKBE-NEXT:    ldr w8, [x0]
++; CHECKBE-NEXT:    and w8, w1, w8
++; CHECKBE-NEXT:    and x0, x8, #0xffff
+ ; CHECKBE-NEXT:    ret
+   %x = load i32, i32* %p, align 4
+   %xz = zext i32 %x to i64
+@@ -43,14 +47,16 @@ define i64 @load32_and16_andr(i32* %p, i64 %y) {
+ define i64 @load32_and16_and_sext(i32* %p, i64 %y) {
+ ; CHECK-LABEL: load32_and16_and_sext:
+ ; CHECK:       // %bb.0:
+-; CHECK-NEXT:    ldrh w8, [x0]
+-; CHECK-NEXT:    and w0, w1, w8
++; CHECK-NEXT:    ldr w8, [x0]
++; CHECK-NEXT:    and w8, w1, w8
++; CHECK-NEXT:    and x0, x8, #0xffff
+ ; CHECK-NEXT:    ret
+ ;
+ ; CHECKBE-LABEL: load32_and16_and_sext:
+ ; CHECKBE:       // %bb.0:
+-; CHECKBE-NEXT:    ldrh w8, [x0, #2]
+-; CHECKBE-NEXT:    and w0, w1, w8
++; CHECKBE-NEXT:    ldr w8, [x0]
++; CHECKBE-NEXT:    and w8, w1, w8
++; CHECKBE-NEXT:    and x0, x8, #0xffff
+ ; CHECKBE-NEXT:    ret
+   %x = load i32, i32* %p, align 4
+   %xz = sext i32 %x to i64
+@@ -62,16 +68,16 @@ define i64 @load32_and16_and_sext(i32* %p, i64 %y) {
+ define i64 @load32_and16_or(i32* %p, i64 %y) {
+ ; CHECK-LABEL: load32_and16_or:
+ ; CHECK:       // %bb.0:
+-; CHECK-NEXT:    ldrh w8, [x0]
+-; CHECK-NEXT:    and w9, w1, #0xffff
+-; CHECK-NEXT:    orr w0, w9, w8
++; CHECK-NEXT:    ldr w8, [x0]
++; CHECK-NEXT:    orr w8, w1, w8
++; CHECK-NEXT:    and x0, x8, #0xffff
+ ; CHECK-NEXT:    ret
+ ;
+ ; CHECKBE-LABEL: load32_and16_or:
+ ; CHECKBE:       // %bb.0:
+-; CHECKBE-NEXT:    ldrh w8, [x0, #2]
+-; CHECKBE-NEXT:    and w9, w1, #0xffff
+-; CHECKBE-NEXT:    orr w0, w9, w8
++; CHECKBE-NEXT:    ldr w8, [x0]
++; CHECKBE-NEXT:    orr w8, w1, w8
++; CHECKBE-NEXT:    and x0, x8, #0xffff
+ ; CHECKBE-NEXT:    ret
+   %x = load i32, i32* %p, align 4
+   %xz = zext i32 %x to i64
+@@ -164,14 +170,16 @@ define i64 @load16_and16(i16* %p, i64 %y) {
+ define i64 @load16_and8(i16* %p, i64 %y) {
+ ; CHECK-LABEL: load16_and8:
+ ; CHECK:       // %bb.0:
+-; CHECK-NEXT:    ldrb w8, [x0]
+-; CHECK-NEXT:    and w0, w1, w8
++; CHECK-NEXT:    ldrh w8, [x0]
++; CHECK-NEXT:    and w8, w1, w8
++; CHECK-NEXT:    and x0, x8, #0xff
+ ; CHECK-NEXT:    ret
+ ;
+ ; CHECKBE-LABEL: load16_and8:
+ ; CHECKBE:       // %bb.0:
+-; CHECKBE-NEXT:    ldrb w8, [x0, #1]
+-; CHECKBE-NEXT:    and w0, w1, w8
++; CHECKBE-NEXT:    ldrh w8, [x0]
++; CHECKBE-NEXT:    and w8, w1, w8
++; CHECKBE-NEXT:    and x0, x8, #0xff
+ ; CHECKBE-NEXT:    ret
+   %x = load i16, i16* %p, align 4
+   %xz = zext i16 %x to i64
+@@ -224,13 +232,15 @@ define i64 @load8_and16_zext(i8* %p, i8 %y) {
+ ; CHECK-LABEL: load8_and16_zext:
+ ; CHECK:       // %bb.0:
+ ; CHECK-NEXT:    ldrb w8, [x0]
+-; CHECK-NEXT:    and w0, w1, w8
++; CHECK-NEXT:    and w8, w1, w8
++; CHECK-NEXT:    and x0, x8, #0xff
+ ; CHECK-NEXT:    ret
+ ;
+ ; CHECKBE-LABEL: load8_and16_zext:
+ ; CHECKBE:       // %bb.0:
+ ; CHECKBE-NEXT:    ldrb w8, [x0]
+-; CHECKBE-NEXT:    and w0, w1, w8
++; CHECKBE-NEXT:    and w8, w1, w8
++; CHECKBE-NEXT:    and x0, x8, #0xff
+ ; CHECKBE-NEXT:    ret
+   %x = load i8, i8* %p, align 4
+   %xz = zext i8 %x to i64
+@@ -286,14 +296,16 @@ define i64 @load8_and16_or(i8* %p, i64 %y) {
+ define i64 @load16_and8_manyext(i16* %p, i32 %y) {
+ ; CHECK-LABEL: load16_and8_manyext:
+ ; CHECK:       // %bb.0:
+-; CHECK-NEXT:    ldrb w8, [x0]
+-; CHECK-NEXT:    and w0, w1, w8
++; CHECK-NEXT:    ldrh w8, [x0]
++; CHECK-NEXT:    and w8, w1, w8
++; CHECK-NEXT:    and x0, x8, #0xff
+ ; CHECK-NEXT:    ret
+ ;
+ ; CHECKBE-LABEL: load16_and8_manyext:
+ ; CHECKBE:       // %bb.0:
+-; CHECKBE-NEXT:    ldrb w8, [x0, #1]
+-; CHECKBE-NEXT:    and w0, w1, w8
++; CHECKBE-NEXT:    ldrh w8, [x0]
++; CHECKBE-NEXT:    and w8, w1, w8
++; CHECKBE-NEXT:    and x0, x8, #0xff
+ ; CHECKBE-NEXT:    ret
+   %x = load i16, i16* %p, align 4
+   %xz = zext i16 %x to i32
+@@ -306,16 +318,18 @@ define i64 @load16_and8_manyext(i16* %p, i32 %y) {
+ define i64 @multiple_load(i16* %p, i32* %q) {
+ ; CHECK-LABEL: multiple_load:
+ ; CHECK:       // %bb.0:
+-; CHECK-NEXT:    ldrb w8, [x0]
+-; CHECK-NEXT:    ldrb w9, [x1]
+-; CHECK-NEXT:    and w0, w9, w8
++; CHECK-NEXT:    ldrh w8, [x0]
++; CHECK-NEXT:    ldr w9, [x1]
++; CHECK-NEXT:    and w8, w9, w8
++; CHECK-NEXT:    and x0, x8, #0xff
+ ; CHECK-NEXT:    ret
+ ;
+ ; CHECKBE-LABEL: multiple_load:
+ ; CHECKBE:       // %bb.0:
+-; CHECKBE-NEXT:    ldrb w8, [x0, #1]
+-; CHECKBE-NEXT:    ldrb w9, [x1, #3]
+-; CHECKBE-NEXT:    and w0, w9, w8
++; CHECKBE-NEXT:    ldrh w8, [x0]
++; CHECKBE-NEXT:    ldr w9, [x1]
++; CHECKBE-NEXT:    and w8, w9, w8
++; CHECKBE-NEXT:    and x0, x8, #0xff
+ ; CHECKBE-NEXT:    ret
+   %x = load i16, i16* %p, align 4
+   %xz = zext i16 %x to i64
+@@ -329,16 +343,18 @@ define i64 @multiple_load(i16* %p, i32* %q) {
+ define i64 @multiple_load_or(i16* %p, i32* %q) {
+ ; CHECK-LABEL: multiple_load_or:
+ ; CHECK:       // %bb.0:
+-; CHECK-NEXT:    ldrb w8, [x0]
+-; CHECK-NEXT:    ldrb w9, [x1]
+-; CHECK-NEXT:    orr w0, w9, w8
++; CHECK-NEXT:    ldrh w8, [x0]
++; CHECK-NEXT:    ldr w9, [x1]
++; CHECK-NEXT:    orr w8, w9, w8
++; CHECK-NEXT:    and x0, x8, #0xff
+ ; CHECK-NEXT:    ret
+ ;
+ ; CHECKBE-LABEL: multiple_load_or:
+ ; CHECKBE:       // %bb.0:
+-; CHECKBE-NEXT:    ldrb w8, [x0, #1]
+-; CHECKBE-NEXT:    ldrb w9, [x1, #3]
+-; CHECKBE-NEXT:    orr w0, w9, w8
++; CHECKBE-NEXT:    ldrh w8, [x0]
++; CHECKBE-NEXT:    ldr w9, [x1]
++; CHECKBE-NEXT:    orr w8, w9, w8
++; CHECKBE-NEXT:    and x0, x8, #0xff
+ ; CHECKBE-NEXT:    ret
+   %x = load i16, i16* %p, align 4
+   %xz = zext i16 %x to i64
+@@ -352,16 +368,16 @@ define i64 @multiple_load_or(i16* %p, i32* %q) {
+ define i64 @load32_and16_zexty(i32* %p, i32 %y) {
+ ; CHECK-LABEL: load32_and16_zexty:
+ ; CHECK:       // %bb.0:
+-; CHECK-NEXT:    ldrh w8, [x0]
+-; CHECK-NEXT:    and w9, w1, #0xffff
+-; CHECK-NEXT:    orr w0, w9, w8
++; CHECK-NEXT:    ldr w8, [x0]
++; CHECK-NEXT:    orr w8, w1, w8
++; CHECK-NEXT:    and x0, x8, #0xffff
+ ; CHECK-NEXT:    ret
+ ;
+ ; CHECKBE-LABEL: load32_and16_zexty:
+ ; CHECKBE:       // %bb.0:
+-; CHECKBE-NEXT:    ldrh w8, [x0, #2]
+-; CHECKBE-NEXT:    and w9, w1, #0xffff
+-; CHECKBE-NEXT:    orr w0, w9, w8
++; CHECKBE-NEXT:    ldr w8, [x0]
++; CHECKBE-NEXT:    orr w8, w1, w8
++; CHECKBE-NEXT:    and x0, x8, #0xffff
+ ; CHECKBE-NEXT:    ret
+   %x = load i32, i32* %p, align 4
+   %xz = zext i32 %x to i64
+@@ -374,16 +390,16 @@ define i64 @load32_and16_zexty(i32* %p, i32 %y) {
+ define i64 @load32_and16_sexty(i32* %p, i32 %y) {
+ ; CHECK-LABEL: load32_and16_sexty:
+ ; CHECK:       // %bb.0:
+-; CHECK-NEXT:    ldrh w8, [x0]
+-; CHECK-NEXT:    and w9, w1, #0xffff
+-; CHECK-NEXT:    orr w0, w9, w8
++; CHECK-NEXT:    ldr w8, [x0]
++; CHECK-NEXT:    orr w8, w1, w8
++; CHECK-NEXT:    and x0, x8, #0xffff
+ ; CHECK-NEXT:    ret
+ ;
+ ; CHECKBE-LABEL: load32_and16_sexty:
+ ; CHECKBE:       // %bb.0:
+-; CHECKBE-NEXT:    ldrh w8, [x0, #2]
+-; CHECKBE-NEXT:    and w9, w1, #0xffff
+-; CHECKBE-NEXT:    orr w0, w9, w8
++; CHECKBE-NEXT:    ldr w8, [x0]
++; CHECKBE-NEXT:    orr w8, w1, w8
++; CHECKBE-NEXT:    and x0, x8, #0xffff
+ ; CHECKBE-NEXT:    ret
+   %x = load i32, i32* %p, align 4
+   %xz = zext i32 %x to i64
+diff --git a/llvm/test/CodeGen/X86/pr35763.ll b/llvm/test/CodeGen/X86/pr35763.ll
+index 53a0a0284d11..8b3e91dc577a 100644
+--- a/llvm/test/CodeGen/X86/pr35763.ll
++++ b/llvm/test/CodeGen/X86/pr35763.ll
+@@ -10,10 +10,10 @@
+ define dso_local void @PR35763() {
+ ; CHECK-LABEL: PR35763:
+ ; CHECK:       # %bb.0: # %entry
+-; CHECK-NEXT:    movzwl z(%rip), %eax
+-; CHECK-NEXT:    movzwl z+2(%rip), %ecx
+-; CHECK-NEXT:    orl %eax, %ecx
+-; CHECK-NEXT:    movq %rcx, tf_3_var_136(%rip)
++; CHECK-NEXT:    movl z(%rip), %eax
++; CHECK-NEXT:    orl z+2(%rip), %eax
++; CHECK-NEXT:    movzwl %ax, %eax
++; CHECK-NEXT:    movq %rax, tf_3_var_136(%rip)
+ ; CHECK-NEXT:    movl z+6(%rip), %eax
+ ; CHECK-NEXT:    movzbl z+10(%rip), %ecx
+ ; CHECK-NEXT:    shlq $32, %rcx
+-- 
+2.35.1.723.g4982287a31-goog
+
diff --git a/patches/cherry/d7dd7ad827a0a78314f3c9b55f4778a6059840f3.patch b/patches/cherry/d7dd7ad827a0a78314f3c9b55f4778a6059840f3.patch
new file mode 100644
index 0000000..34c9092
--- /dev/null
+++ b/patches/cherry/d7dd7ad827a0a78314f3c9b55f4778a6059840f3.patch
@@ -0,0 +1,56 @@
+From d7dd7ad827a0a78314f3c9b55f4778a6059840f3 Mon Sep 17 00:00:00 2001
+From: Kirill Stoimenov <kstoimenov@google.com>
+Date: Tue, 1 Feb 2022 20:39:29 +0000
+Subject: [PATCH] Revert "[ASan] Not linking asan_static library for DSO."
+
+This reverts commit cf730d8ce1341ba593144df2e2bc8411238e04c3. It turned out that D118184 is causing segfaults in some situations.
+
+Reviewed By: vitalybuka, kda
+
+Differential Revision: https://reviews.llvm.org/D118739
+---
+ clang/lib/Driver/ToolChains/CommonArgs.cpp | 8 ++++----
+ clang/test/Driver/sanitizer-ld.c           | 2 +-
+ 2 files changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
+index 87f1c8d0c998..6364cd133e0b 100644
+--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
++++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
+@@ -845,16 +845,16 @@ collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
+   if (SanArgs.needsStatsRt() && SanArgs.linkRuntimes())
+     StaticRuntimes.push_back("stats_client");
+ 
++  // Always link the static runtime regardless of DSO or executable.
++  if (SanArgs.needsAsanRt())
++    HelperStaticRuntimes.push_back("asan_static");
++
+   // Collect static runtimes.
+   if (Args.hasArg(options::OPT_shared)) {
+     // Don't link static runtimes into DSOs.
+     return;
+   }
+ 
+-  // Always link the static runtime for executable.
+-  if (SanArgs.needsAsanRt())
+-    HelperStaticRuntimes.push_back("asan_static");
+-
+   // Each static runtime that has a DSO counterpart above is excluded below,
+   // but runtimes that exist only as static are not affected by needsSharedRt.
+ 
+diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c
+index d96cddb31d68..966edbd7d038 100644
+--- a/clang/test/Driver/sanitizer-ld.c
++++ b/clang/test/Driver/sanitizer-ld.c
+@@ -39,7 +39,7 @@
+ // RUN:     --sysroot=%S/Inputs/basic_linux_tree \
+ // RUN:   | FileCheck --check-prefix=CHECK-ASAN-SHARED-LINUX %s
+ //
+-// CHECK-ASAN-SHARED-LINUX-NOT: libclang_rt.asan_static-x86_64
++// CHECK-ASAN-SHARED-LINUX: libclang_rt.asan_static-x86_64
+ // CHECK-ASAN-SHARED-LINUX-NOT: libclang_rt.asan-x86_64
+ 
+ // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+-- 
+2.35.1.723.g4982287a31-goog
+
diff --git a/patches/cherry/f69f23396d32c95dacf3765bc63af02b23ccff3e.patch b/patches/cherry/f69f23396d32c95dacf3765bc63af02b23ccff3e.patch
new file mode 100644
index 0000000..d445e63
--- /dev/null
+++ b/patches/cherry/f69f23396d32c95dacf3765bc63af02b23ccff3e.patch
@@ -0,0 +1,193 @@
+From f69f23396d32c95dacf3765bc63af02b23ccff3e Mon Sep 17 00:00:00 2001
+From: David Blaikie <dblaikie@gmail.com>
+Date: Mon, 31 Jan 2022 18:27:39 -0800
+Subject: [PATCH] Revert "DebugInfo: Don't put types in type units if they
+ reference internal linkage types"
+
+This reverts commit ab4756338c5b2216d52d9152b2f7e65f233c4dac.
+
+Breaks some cases, including this:
+
+namespace {
+template <typename> struct a {};
+} // namespace
+class c {
+  c();
+};
+class b {
+  b();
+  a<c> ax;
+};
+b::b() {}
+c::c() {}
+
+By producing a reference to a type unit for "c" but not producing the type unit.
+---
+ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 12 +++---------
+ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h   |  3 ---
+ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp  | 22 +++-------------------
+ llvm/test/DebugInfo/X86/tu-to-non-tu.ll    | 22 +++++++++++++---------
+ 4 files changed, 19 insertions(+), 40 deletions(-)
+
+diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+index 680b9586228f..609b568f28be 100644
+--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
++++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+@@ -3367,8 +3367,7 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
+   // Fast path if we're building some type units and one has already used the
+   // address pool we know we're going to throw away all this work anyway, so
+   // don't bother building dependent types.
+-  if (!TypeUnitsUnderConstruction.empty() &&
+-      (AddrPool.hasBeenUsed() || SeenLocalType))
++  if (!TypeUnitsUnderConstruction.empty() && AddrPool.hasBeenUsed())
+     return;
+ 
+   auto Ins = TypeSignatures.insert(std::make_pair(CTy, 0));
+@@ -3379,7 +3378,6 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
+ 
+   bool TopLevelType = TypeUnitsUnderConstruction.empty();
+   AddrPool.resetUsedFlag();
+-  SeenLocalType = false;
+ 
+   auto OwnedUnit = std::make_unique<DwarfTypeUnit>(CU, Asm, this, &InfoHolder,
+                                                     getDwoLineTable(CU));
+@@ -3423,7 +3421,7 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
+ 
+     // Types referencing entries in the address table cannot be placed in type
+     // units.
+-    if (AddrPool.hasBeenUsed() || SeenLocalType) {
++    if (AddrPool.hasBeenUsed()) {
+ 
+       // Remove all the types built while building this type.
+       // This is pessimistic as some of these types might not be dependent on
+@@ -3451,18 +3449,14 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
+ 
+ DwarfDebug::NonTypeUnitContext::NonTypeUnitContext(DwarfDebug *DD)
+     : DD(DD),
+-      TypeUnitsUnderConstruction(std::move(DD->TypeUnitsUnderConstruction)),
+-      AddrPoolUsed(DD->AddrPool.hasBeenUsed()),
+-      SeenLocalType(DD->SeenLocalType) {
++      TypeUnitsUnderConstruction(std::move(DD->TypeUnitsUnderConstruction)), AddrPoolUsed(DD->AddrPool.hasBeenUsed()) {
+   DD->TypeUnitsUnderConstruction.clear();
+   DD->AddrPool.resetUsedFlag();
+-  DD->SeenLocalType = false;
+ }
+ 
+ DwarfDebug::NonTypeUnitContext::~NonTypeUnitContext() {
+   DD->TypeUnitsUnderConstruction = std::move(TypeUnitsUnderConstruction);
+   DD->AddrPool.resetUsedFlag(AddrPoolUsed);
+-  DD->SeenLocalType = SeenLocalType;
+ }
+ 
+ DwarfDebug::NonTypeUnitContext DwarfDebug::enterNonTypeUnitContext() {
+diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+index 0043000652e8..4e1a1b1e068d 100644
+--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
++++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+@@ -433,7 +433,6 @@ private:
+   DenseMap<const DIStringType *, unsigned> StringTypeLocMap;
+ 
+   AddressPool AddrPool;
+-  bool SeenLocalType = false;
+ 
+   /// Accelerator tables.
+   AccelTable<DWARF5AccelTableData> AccelDebugNames;
+@@ -672,7 +671,6 @@ public:
+     DwarfDebug *DD;
+     decltype(DwarfDebug::TypeUnitsUnderConstruction) TypeUnitsUnderConstruction;
+     bool AddrPoolUsed;
+-    bool SeenLocalType;
+     friend class DwarfDebug;
+     NonTypeUnitContext(DwarfDebug *DD);
+   public:
+@@ -681,7 +679,6 @@ public:
+   };
+ 
+   NonTypeUnitContext enterNonTypeUnitContext();
+-  void seenLocalType() { SeenLocalType = true; }
+ 
+   /// Add a label so that arange data can be generated for it.
+   void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
+diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+index 132579aedbc9..5a2bd479f277 100644
+--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
++++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+@@ -596,8 +596,10 @@ DIE *DwarfUnit::createTypeDIE(const DIScope *Context, DIE &ContextDIE,
+       // Skip updating the accelerator tables since this is not the full type.
+       if (MDString *TypeId = CTy->getRawIdentifier())
+         DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
+-      else
++      else {
++        auto X = DD->enterNonTypeUnitContext();
+         finishNonUnitTypeDIE(TyDIE, CTy);
++      }
+       return &TyDIE;
+     }
+     constructTypeDIE(TyDIE, CTy);
+@@ -1851,23 +1853,5 @@ void DwarfTypeUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {
+     addString(D, dwarf::DW_AT_name, Name);
+   if (Name.startswith("_STN") || !Name.contains('<'))
+     addTemplateParams(D, CTy->getTemplateParams());
+-  // If the type is in an anonymous namespace, we can't reference it from a TU
+-  // (since the type would be CU local and the TU doesn't specify which TU has
+-  // the appropriate type definition) - so flag this emission as such and skip
+-  // the rest of the emission now since we're going to throw out all this work
+-  // and put the outer/referencing type in the CU instead.
+-  // FIXME: Probably good to generalize this to a DICompositeType flag populated
+-  // by the frontend, then we could use that to have types that can have
+-  // decl+def merged by LTO but where the definition still doesn't go in a type
+-  // unit because the type has only one definition.
+-  for (DIScope *S = CTy->getScope(); S; S = S->getScope()) {
+-    if (auto *NS = dyn_cast<DINamespace>(S)) {
+-      if (NS->getName().empty()) {
+-        DD->seenLocalType();
+-        break;
+-      }
+-    }
+-  }
+-  auto X = DD->enterNonTypeUnitContext();
+   getCU().createTypeDIE(CTy);
+ }
+diff --git a/llvm/test/DebugInfo/X86/tu-to-non-tu.ll b/llvm/test/DebugInfo/X86/tu-to-non-tu.ll
+index 517872d2b92e..4b8ea04bedc5 100644
+--- a/llvm/test/DebugInfo/X86/tu-to-non-tu.ll
++++ b/llvm/test/DebugInfo/X86/tu-to-non-tu.ll
+@@ -1,15 +1,17 @@
+ ; RUN: llc -filetype=obj -O0 -generate-type-units -mtriple=x86_64-unknown-linux-gnu < %s \
+ ; RUN:     | llvm-dwarfdump -debug-info -debug-types - | FileCheck %s
+ 
+-; Test that a type unit referencing a non-type unit produces a declaration of
+-; the referent in the referee.
+-
+-; Also check that an attempt to reference an internal linkage (defined in an anonymous
+-; namespace) type from a type unit (could happen with a pimpl idiom, for instance -
+-; it does mean the linkage-having type can only be defined in one translation
+-; unit anyway) forces the referent to not be placed in a type unit (because the
+-; declaration of the internal linkage type would be ambiguous/wouldn't allow a
+-; consumer to find the definition with certainty)
++; Test that a type unit referencing a non-type unit (in this case, it's
++; bordering on an ODR violation - a type with linkage references a type without
++; linkage, so there's no way for the first type to be defined in more than one
++; translation unit, so there's no need for it to be in a type unit - but this
++; is quirky/rare and an easy way to test a broader issue). The type unit should
++; not end up with a whole definition of the referenced type - instead it should
++; have a declaration of the type, while the definition remains in the primary
++; CU.
++; (again, arguably in this instance - since the type is only referenced once, it
++; could go in the TU only - but that requires tracking usage & then deciding
++; where to put types, which isn't worthwhile right now)
+ 
+ ; Built from the following source, compiled with this command:
+ ; $ clang++-tot decl.cpp -g -fdebug-types-section -c
+@@ -118,6 +120,8 @@
+ ; CHECK-NEXT:   DW_AT_declaration       (true)
+ ; CHECK-NEXT:   DW_AT_signature (0xb1cde890d320f5c2)
+ 
++; CHECK: DW_TAG_namespace
++; CHECK-NOT: {{DW_AT_name|DW_TAG}}
+ ; CHECK: DW_TAG_structure_type
+ ; CHECK-NOT: DW_TAG
+ ; CHECK: DW_AT_name {{.*}}"non_tu"
+-- 
+2.35.1.723.g4982287a31-goog
+