[llvm] [AArch64][GlobalISel] Optimize shl lowering by removing G_ZEXT (PR #199870)

Yeongu Choe via llvm-commits llvm-commits at lists.llvm.org
Tue May 26 22:04:18 PDT 2026


https://github.com/YeonguChoe created https://github.com/llvm/llvm-project/pull/199870

When Lowering `shl` instruction, it creates

```llvm
G_ZEXT
G_SHL
```

In AArch64 architecture, `G_SHL` (shift left) operation is lowered to `LSL` operation.
`LSL` operation internally does lower bit extraction, so it does not require lower bit extraction (5 bits for 32bit, 6 bits for 64bit).

This optimization captures

```llvm
%reg1 = G_ZEXT %reg0
G_SHL %reg2, %reg1
```

pattern, and converts to

```llvm
G_SHL %reg2, (G_ANYEXT %reg0)
```

### Reference

- AArch64 LSL operation: https://developer.arm.com/documentation/ddi0602/2026-03/Base-Instructions/LSL--register---Logical-shift-left--register---an-alias-of-LSLV-?lang=en
- G_SHL: https://llvm.org/docs/GlobalISel/GenericOpcode.html#g-shl-g-lshr-g-ashr
- G_ZEXT: https://llvm.org/docs/GlobalISel/GenericOpcode.html#g-zext
- G_ANYEXT: https://llvm.org/docs/GlobalISel/GenericOpcode.html#g-anyext

>From 8bb43785a3ccdb12790ea7a1768bf389c7e7036e Mon Sep 17 00:00:00 2001
From: Yeongu Choe <yeongu.choe at icloud.com>
Date: Wed, 27 May 2026 00:46:39 -0400
Subject: [PATCH] [AArch64][GlobalISel] Optimize shl lowering by removing
 G_ZEXT

Removes and instruction (AArch64 ISA) when lowering shl (LLVM IR).
LSL operation in AArch64 handles zero extension including lower bit extraction.
---
 llvm/lib/Target/AArch64/AArch64Combine.td     |  10 +-
 .../GISel/AArch64PostLegalizerCombiner.cpp    |  78 ++
 .../AArch64/GlobalISel/combine-zext-shl.ll    |  20 +
 .../GlobalISel/split-wide-shifts-multiway.ll  | 976 +++++++++---------
 llvm/test/CodeGen/AArch64/frem-power2.ll      |   6 +-
 llvm/test/CodeGen/AArch64/fsh.ll              | 272 +++--
 llvm/test/CodeGen/AArch64/funnel-shift.ll     | 118 +--
 ...ist-and-by-const-from-shl-in-eqcmp-zero.ll |  24 +-
 llvm/test/CodeGen/AArch64/select_const.ll     |   1 -
 llvm/test/CodeGen/AArch64/shift.ll            |  28 +-
 10 files changed, 809 insertions(+), 724 deletions(-)
 create mode 100644 llvm/test/CodeGen/AArch64/GlobalISel/combine-zext-shl.ll

diff --git a/llvm/lib/Target/AArch64/AArch64Combine.td b/llvm/lib/Target/AArch64/AArch64Combine.td
index 44b86dac27df2..2f6826a8771c2 100644
--- a/llvm/lib/Target/AArch64/AArch64Combine.td
+++ b/llvm/lib/Target/AArch64/AArch64Combine.td
@@ -357,6 +357,13 @@ def combine_mul_cmlt : GICombineRule<
   (apply [{ applyCombineMulCMLT(*${root}, MRI, B, ${matchinfo}); }])
 >;
 
+def remove_zext_when_lowering_shl : GICombineRule<
+  (defs root:$root, register_matchinfo:$matchinfo),
+  (match (wip_match_opcode G_SHL):$root,
+         [{ return matchRemoveZextWhenLoweringShl(*${root}, MRI, ${matchinfo}); }]),
+  (apply [{ applyRemoveZextWhenLoweringShl(*${root}, MRI, B, Observer, ${matchinfo}); }])
+>;
+
 // Post-legalization combines which should happen at all optimization levels.
 // (E.g. ones that facilitate matching for the selector) For example, matching
 // pseudos.
@@ -395,5 +402,6 @@ def AArch64PostLegalizerCombiner
                         combine_mul_cmlt, combine_use_vector_truncate,
                         extmultomull, subaddmulreassoc, truncsat_combines,
                         lshr_of_trunc_of_lshr,
-                        funnel_shift_from_or_shift_constants_are_legal]> {
+                        funnel_shift_from_or_shift_constants_are_legal,
+                        remove_zext_when_lowering_shl]> {
 }
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
index 3a0c0e7494f41..a4aacedd01498 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
@@ -588,6 +588,84 @@ static void applySubAddMulReassoc(MachineInstr &MI, MachineInstr &Sub,
   Observer.changingInstr(MI);
 }
 
+bool matchRemoveZextWhenLoweringShl(MachineInstr &MI, MachineRegisterInfo &MRI,
+                                    Register &MatchInfo) {
+  // check Opcode is G_SHL
+  assert(MI.getOpcode() == TargetOpcode::G_SHL && "Opcode is not G_SHL");
+
+  // check the shape of operation is correct
+
+  // check destination register is 32 bit or 64 bit scalar type
+  LLT DstTy = MRI.getType(MI.getOperand(0).getReg());
+  if (DstTy.isVector()) {
+    return false;
+  }
+  unsigned BW = DstTy.getScalarSizeInBits();
+  if (BW != 32 && BW != 64) {
+    return false;
+  }
+
+  // check amount register originated from G_ZEXT
+  Register AmtReg = MI.getOperand(2).getReg();
+  MachineInstr *AmtDef = MRI.getVRegDef(AmtReg);
+  if (!AmtDef)
+    return false;
+
+  // check if the low 5 or 6 bits of the mask in G_AND %src, mask are all set
+  // AmtDef = G_AND %src, 0xFF
+  if (AmtDef->getOpcode() == TargetOpcode::G_AND) {
+    auto IsConstantMask =
+        getIConstantVRegValWithLookThrough(AmtDef->getOperand(2).getReg(), MRI);
+    if (!IsConstantMask)
+      return false;
+    APInt StandardMask =
+        APInt::getLowBitsSet(IsConstantMask->Value.getBitWidth(), Log2_32(BW));
+    if ((IsConstantMask->Value & StandardMask) != StandardMask)
+      return false;
+
+    MatchInfo = AmtDef->getOperand(1).getReg();
+    return true;
+  }
+
+  if (AmtDef->getOpcode() != TargetOpcode::G_ZEXT) {
+    return false;
+  }
+
+  // check G_ZEXT input register is 5bits or more and scalar type
+  Register Src = AmtDef->getOperand(1).getReg();
+  LLT SrcTy = MRI.getType(Src);
+  if (SrcTy.isVector()) {
+    return false;
+  }
+  if (SrcTy.getScalarSizeInBits() < Log2_32(BW)) {
+    return false;
+  }
+
+  // proceed if tests have passed
+  MatchInfo = Src;
+  return true;
+}
+
+void applyRemoveZextWhenLoweringShl(MachineInstr &MI, MachineRegisterInfo &MRI,
+                                    MachineIRBuilder &B,
+                                    GISelChangeObserver &Observer,
+                                    Register &MatchInfo) {
+  Register OriginalShiftAmt = MI.getOperand(2).getReg();
+  LLT OriginalShiftTy = MRI.getType(OriginalShiftAmt);
+  LLT SrcTy = MRI.getType(MatchInfo);
+
+  Register NewShiftAmt = MatchInfo;
+  // if shift amount is zero extended, replace it with new shift amount
+  if (OriginalShiftTy != SrcTy) {
+    B.setInstrAndDebugLoc(MI);
+    NewShiftAmt = B.buildAnyExt(OriginalShiftTy, MatchInfo).getReg(0);
+  }
+
+  Observer.changingInstr(MI);
+  MI.getOperand(2).setReg(NewShiftAmt);
+  Observer.changedInstr(MI);
+}
+
 class AArch64PostLegalizerCombinerImpl : public Combiner {
 protected:
   const CombinerHelper Helper;
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/combine-zext-shl.ll b/llvm/test/CodeGen/AArch64/GlobalISel/combine-zext-shl.ll
new file mode 100644
index 0000000000000..008ae8b1cc91f
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/combine-zext-shl.ll
@@ -0,0 +1,20 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=aarch64-- -global-isel -o - %s | FileCheck %s
+
+define i8 @test_shl_i8(i8 %a, i8 %b) {
+; CHECK-LABEL: test_shl_i8:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    lsl w0, w0, w1
+; CHECK-NEXT:    ret
+  %r = shl i8 %a, %b
+  ret i8 %r
+}
+
+define i16 @test_shl_i16(i16 %a, i16 %b) {
+; CHECK-LABEL: test_shl_i16:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    lsl w0, w0, w1
+; CHECK-NEXT:    ret
+  %r = shl i16 %a, %b
+  ret i16 %r
+}
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/split-wide-shifts-multiway.ll b/llvm/test/CodeGen/AArch64/GlobalISel/split-wide-shifts-multiway.ll
index d669c49cb019b..3b0a476ccd524 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/split-wide-shifts-multiway.ll
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/split-wide-shifts-multiway.ll
@@ -85,14 +85,15 @@ define void @test_shl_i512(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    .cfi_offset w26, -64
 ; GISEL-NEXT:    .cfi_offset w27, -72
 ; GISEL-NEXT:    .cfi_offset w28, -80
-; GISEL-NEXT:    ldp x11, x15, [x1]
+; GISEL-NEXT:    ldp x11, x14, [x1]
+; GISEL-NEXT:    ; kill: def $w2 killed $w2 def $x2
 ; GISEL-NEXT:    mov w8, w2
 ; GISEL-NEXT:    lsr x9, x8, #6
-; GISEL-NEXT:    and x14, x8, #0x3f
-; GISEL-NEXT:    mov w13, #64 ; =0x40
-; GISEL-NEXT:    sub x16, x13, x14
+; GISEL-NEXT:    and x13, x8, #0x3f
+; GISEL-NEXT:    mov w15, #64 ; =0x40
+; GISEL-NEXT:    sub x15, x15, x13
 ; GISEL-NEXT:    ldp x3, x6, [x1, #16]
-; GISEL-NEXT:    lsl x10, x11, x14
+; GISEL-NEXT:    lsl x10, x11, x2
 ; GISEL-NEXT:    cmp x9, #0
 ; GISEL-NEXT:    ldp x20, x21, [x1, #32]
 ; GISEL-NEXT:    csel x12, x10, xzr, eq
@@ -101,7 +102,7 @@ define void @test_shl_i512(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    cmp x9, #2
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    lsr x26, x21, x16
+; GISEL-NEXT:    lsr x26, x21, x15
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #4
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
@@ -112,36 +113,36 @@ define void @test_shl_i512(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    cmp x9, #7
 ; GISEL-NEXT:    csel x13, xzr, x12, eq
 ; GISEL-NEXT:    cmp x8, #0
-; GISEL-NEXT:    lsr x12, x11, x16
+; GISEL-NEXT:    lsr x12, x11, x15
 ; GISEL-NEXT:    csel x13, x11, x13, eq
-; GISEL-NEXT:    lsl x11, x15, x14
+; GISEL-NEXT:    lsl x11, x14, x2
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x17, xzr, x12, eq
+; GISEL-NEXT:    csel x16, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    orr x17, x11, x17
-; GISEL-NEXT:    csel x17, x17, xzr, eq
+; GISEL-NEXT:    orr x16, x11, x16
+; GISEL-NEXT:    csel x16, x16, xzr, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    csel x17, x10, x17, eq
+; GISEL-NEXT:    csel x16, x10, x16, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    csel x17, xzr, x17, eq
+; GISEL-NEXT:    csel x16, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    csel x17, xzr, x17, eq
+; GISEL-NEXT:    csel x16, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #4
-; GISEL-NEXT:    csel x17, xzr, x17, eq
+; GISEL-NEXT:    csel x16, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #5
-; GISEL-NEXT:    csel x17, xzr, x17, eq
+; GISEL-NEXT:    csel x16, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #6
-; GISEL-NEXT:    csel x17, xzr, x17, eq
+; GISEL-NEXT:    csel x16, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #7
-; GISEL-NEXT:    csel x2, xzr, x17, eq
+; GISEL-NEXT:    csel x17, xzr, x16, eq
 ; GISEL-NEXT:    cmp x8, #0
-; GISEL-NEXT:    lsr x17, x15, x16
-; GISEL-NEXT:    csel x15, x15, x2, eq
-; GISEL-NEXT:    lsl x2, x3, x14
+; GISEL-NEXT:    lsr x16, x14, x15
+; GISEL-NEXT:    csel x14, x14, x17, eq
+; GISEL-NEXT:    lsl x17, x3, x2
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x4, xzr, x17, eq
+; GISEL-NEXT:    csel x4, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    orr x4, x2, x4
+; GISEL-NEXT:    orr x4, x17, x4
 ; GISEL-NEXT:    csel x4, x4, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x5, xzr, x12, eq
@@ -161,18 +162,18 @@ define void @test_shl_i512(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    cmp x9, #7
 ; GISEL-NEXT:    csel x5, xzr, x4, eq
 ; GISEL-NEXT:    cmp x8, #0
-; GISEL-NEXT:    lsr x4, x3, x16
+; GISEL-NEXT:    lsr x4, x3, x15
 ; GISEL-NEXT:    csel x3, x3, x5, eq
-; GISEL-NEXT:    lsl x5, x6, x14
+; GISEL-NEXT:    lsl x5, x6, x2
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x7, xzr, x4, eq
 ; GISEL-NEXT:    cmp x9, #0
 ; GISEL-NEXT:    orr x7, x5, x7
 ; GISEL-NEXT:    csel x7, x7, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x19, xzr, x17, eq
+; GISEL-NEXT:    csel x19, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    orr x19, x2, x19
+; GISEL-NEXT:    orr x19, x17, x19
 ; GISEL-NEXT:    csel x7, x19, x7, eq
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x19, xzr, x12, eq
@@ -190,9 +191,9 @@ define void @test_shl_i512(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    cmp x9, #7
 ; GISEL-NEXT:    csel x19, xzr, x7, eq
 ; GISEL-NEXT:    cmp x8, #0
-; GISEL-NEXT:    lsr x7, x6, x16
+; GISEL-NEXT:    lsr x7, x6, x15
 ; GISEL-NEXT:    csel x6, x6, x19, eq
-; GISEL-NEXT:    lsl x19, x20, x14
+; GISEL-NEXT:    lsl x19, x20, x2
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x22, xzr, x7, eq
 ; GISEL-NEXT:    cmp x9, #0
@@ -204,9 +205,9 @@ define void @test_shl_i512(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    orr x23, x5, x23
 ; GISEL-NEXT:    csel x22, x23, x22, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x23, xzr, x17, eq
+; GISEL-NEXT:    csel x23, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    orr x23, x2, x23
+; GISEL-NEXT:    orr x23, x17, x23
 ; GISEL-NEXT:    csel x22, x23, x22, eq
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x23, xzr, x12, eq
@@ -222,9 +223,9 @@ define void @test_shl_i512(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    cmp x9, #7
 ; GISEL-NEXT:    csel x23, xzr, x22, eq
 ; GISEL-NEXT:    cmp x8, #0
-; GISEL-NEXT:    lsr x22, x20, x16
+; GISEL-NEXT:    lsr x22, x20, x15
 ; GISEL-NEXT:    csel x20, x20, x23, eq
-; GISEL-NEXT:    lsl x23, x21, x14
+; GISEL-NEXT:    lsl x23, x21, x2
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x24, xzr, x22, eq
 ; GISEL-NEXT:    cmp x9, #0
@@ -241,9 +242,9 @@ define void @test_shl_i512(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    orr x25, x5, x25
 ; GISEL-NEXT:    csel x24, x25, x24, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x25, xzr, x17, eq
+; GISEL-NEXT:    csel x25, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    orr x25, x2, x25
+; GISEL-NEXT:    orr x25, x17, x25
 ; GISEL-NEXT:    csel x24, x25, x24, eq
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x25, xzr, x12, eq
@@ -256,18 +257,18 @@ define void @test_shl_i512(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    ldp x25, x1, [x1, #48]
 ; GISEL-NEXT:    csel x24, xzr, x24, eq
 ; GISEL-NEXT:    cmp x9, #7
-; GISEL-NEXT:    stp x13, x15, [x0]
+; GISEL-NEXT:    stp x13, x14, [x0]
 ; GISEL-NEXT:    csel x24, xzr, x24, eq
 ; GISEL-NEXT:    cmp x8, #0
 ; GISEL-NEXT:    stp x3, x6, [x0, #16]
 ; GISEL-NEXT:    csel x21, x21, x24, eq
-; GISEL-NEXT:    lsl x24, x25, x14
+; GISEL-NEXT:    lsl x24, x25, x2
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x27, xzr, x26, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    lsr x16, x25, x16
+; GISEL-NEXT:    lsr x15, x25, x15
 ; GISEL-NEXT:    orr x27, x24, x27
-; GISEL-NEXT:    lsl x14, x1, x14
+; GISEL-NEXT:    lsl x2, x1, x2
 ; GISEL-NEXT:    stp x20, x21, [x0, #32]
 ; GISEL-NEXT:    csel x27, x27, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
@@ -286,9 +287,9 @@ define void @test_shl_i512(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    orr x28, x5, x28
 ; GISEL-NEXT:    csel x27, x28, x27, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x28, xzr, x17, eq
+; GISEL-NEXT:    csel x28, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #4
-; GISEL-NEXT:    orr x28, x2, x28
+; GISEL-NEXT:    orr x28, x17, x28
 ; GISEL-NEXT:    csel x27, x28, x27, eq
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x28, xzr, x12, eq
@@ -302,38 +303,38 @@ define void @test_shl_i512(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    cmp x8, #0
 ; GISEL-NEXT:    csel x25, x25, x27, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x16, xzr, x16, eq
+; GISEL-NEXT:    csel x15, xzr, x15, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    orr x14, x14, x16
-; GISEL-NEXT:    csel x14, x14, xzr, eq
+; GISEL-NEXT:    orr x15, x2, x15
+; GISEL-NEXT:    csel x15, x15, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x16, xzr, x26, eq
+; GISEL-NEXT:    csel x2, xzr, x26, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    orr x16, x24, x16
-; GISEL-NEXT:    csel x14, x16, x14, eq
+; GISEL-NEXT:    orr x2, x24, x2
+; GISEL-NEXT:    csel x15, x2, x15, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x16, xzr, x22, eq
+; GISEL-NEXT:    csel x2, xzr, x22, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    orr x16, x23, x16
+; GISEL-NEXT:    orr x2, x23, x2
 ; GISEL-NEXT:    ldp x22, x21, [sp, #48] ; 16-byte Folded Reload
-; GISEL-NEXT:    csel x14, x16, x14, eq
+; GISEL-NEXT:    csel x15, x2, x15, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x16, xzr, x7, eq
+; GISEL-NEXT:    csel x2, xzr, x7, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    orr x16, x19, x16
+; GISEL-NEXT:    orr x2, x19, x2
 ; GISEL-NEXT:    ldp x20, x19, [sp, #64] ; 16-byte Folded Reload
-; GISEL-NEXT:    csel x14, x16, x14, eq
+; GISEL-NEXT:    csel x15, x2, x15, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x16, xzr, x4, eq
+; GISEL-NEXT:    csel x2, xzr, x4, eq
 ; GISEL-NEXT:    cmp x9, #4
-; GISEL-NEXT:    orr x16, x5, x16
+; GISEL-NEXT:    orr x2, x5, x2
 ; GISEL-NEXT:    ldp x24, x23, [sp, #32] ; 16-byte Folded Reload
-; GISEL-NEXT:    csel x14, x16, x14, eq
+; GISEL-NEXT:    csel x15, x2, x15, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x16, xzr, x17, eq
+; GISEL-NEXT:    csel x16, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #5
-; GISEL-NEXT:    orr x16, x2, x16
-; GISEL-NEXT:    csel x13, x16, x14, eq
+; GISEL-NEXT:    orr x16, x17, x16
+; GISEL-NEXT:    csel x13, x16, x15, eq
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #6
@@ -1219,14 +1220,14 @@ define void @test_shl_i1024(ptr %result, ptr %input, i32 %shift) {
 ;
 ; GISEL-LABEL: test_shl_i1024:
 ; GISEL:       ; %bb.0: ; %entry
-; GISEL-NEXT:    sub sp, sp, #432
-; GISEL-NEXT:    stp x28, x27, [sp, #336] ; 16-byte Folded Spill
-; GISEL-NEXT:    stp x26, x25, [sp, #352] ; 16-byte Folded Spill
-; GISEL-NEXT:    stp x24, x23, [sp, #368] ; 16-byte Folded Spill
-; GISEL-NEXT:    stp x22, x21, [sp, #384] ; 16-byte Folded Spill
-; GISEL-NEXT:    stp x20, x19, [sp, #400] ; 16-byte Folded Spill
-; GISEL-NEXT:    stp x29, x30, [sp, #416] ; 16-byte Folded Spill
-; GISEL-NEXT:    .cfi_def_cfa_offset 432
+; GISEL-NEXT:    sub sp, sp, #448
+; GISEL-NEXT:    stp x28, x27, [sp, #352] ; 16-byte Folded Spill
+; GISEL-NEXT:    stp x26, x25, [sp, #368] ; 16-byte Folded Spill
+; GISEL-NEXT:    stp x24, x23, [sp, #384] ; 16-byte Folded Spill
+; GISEL-NEXT:    stp x22, x21, [sp, #400] ; 16-byte Folded Spill
+; GISEL-NEXT:    stp x20, x19, [sp, #416] ; 16-byte Folded Spill
+; GISEL-NEXT:    stp x29, x30, [sp, #432] ; 16-byte Folded Spill
+; GISEL-NEXT:    .cfi_def_cfa_offset 448
 ; GISEL-NEXT:    .cfi_offset w30, -8
 ; GISEL-NEXT:    .cfi_offset w29, -16
 ; GISEL-NEXT:    .cfi_offset w19, -24
@@ -1240,46 +1241,44 @@ define void @test_shl_i1024(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    .cfi_offset w27, -88
 ; GISEL-NEXT:    .cfi_offset w28, -96
 ; GISEL-NEXT:    ldp x10, x11, [x1]
+; GISEL-NEXT:    ; kill: def $w2 killed $w2 def $x2
 ; GISEL-NEXT:    mov w8, w2
 ; GISEL-NEXT:    lsr x9, x8, #6
-; GISEL-NEXT:    and x12, x8, #0x3f
-; GISEL-NEXT:    str x0, [sp, #144] ; 8-byte Spill
-; GISEL-NEXT:    and x14, x8, #0x3f
 ; GISEL-NEXT:    mov w13, #64 ; =0x40
-; GISEL-NEXT:    and x16, x8, #0x3f
-; GISEL-NEXT:    lsl x0, x10, x12
-; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    sub x2, x13, x14
-; GISEL-NEXT:    lsr x3, x10, x2
-; GISEL-NEXT:    lsl x6, x11, x14
 ; GISEL-NEXT:    and x14, x8, #0x3f
-; GISEL-NEXT:    csel x12, x0, xzr, eq
+; GISEL-NEXT:    sub x24, x13, x14
+; GISEL-NEXT:    str x0, [sp, #136] ; 8-byte Spill
+; GISEL-NEXT:    mov x4, x2
+; GISEL-NEXT:    lsl x15, x10, x2
+; GISEL-NEXT:    cmp x9, #0
+; GISEL-NEXT:    lsr x17, x10, x24
+; GISEL-NEXT:    lsl x28, x11, x2
+; GISEL-NEXT:    lsr x3, x11, x24
+; GISEL-NEXT:    mov x19, x1
+; GISEL-NEXT:    csel x12, x15, xzr, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    lsr x20, x11, x2
+; GISEL-NEXT:    mov x23, x15
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    mov x24, x0
+; GISEL-NEXT:    mov x5, x4
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    mov x7, x3
+; GISEL-NEXT:    mov x20, x19
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #4
-; GISEL-NEXT:    mov x28, x1
+; GISEL-NEXT:    mov x21, x5
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #5
-; GISEL-NEXT:    and x21, x8, #0x3f
+; GISEL-NEXT:    str x20, [sp, #344] ; 8-byte Spill
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #6
-; GISEL-NEXT:    str x6, [sp, #24] ; 8-byte Spill
+; GISEL-NEXT:    str x28, [sp, #312] ; 8-byte Spill
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #7
-; GISEL-NEXT:    str x28, [sp, #304] ; 8-byte Spill
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #8
-; GISEL-NEXT:    str x7, [sp, #272] ; 8-byte Spill
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #9
-; GISEL-NEXT:    str x20, [sp, #112] ; 8-byte Spill
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #10
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
@@ -1296,13 +1295,13 @@ define void @test_shl_i1024(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    cmp x8, #0
 ; GISEL-NEXT:    csel x10, x10, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    str x10, [sp, #232] ; 8-byte Spill
-; GISEL-NEXT:    csel x10, xzr, x3, eq
+; GISEL-NEXT:    str x10, [sp, #216] ; 8-byte Spill
+; GISEL-NEXT:    csel x10, xzr, x17, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    orr x10, x6, x10
+; GISEL-NEXT:    orr x10, x28, x10
 ; GISEL-NEXT:    csel x10, x10, xzr, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    csel x10, x0, x10, eq
+; GISEL-NEXT:    csel x10, x15, x10, eq
 ; GISEL-NEXT:    cmp x9, #2
 ; GISEL-NEXT:    csel x10, xzr, x10, eq
 ; GISEL-NEXT:    cmp x9, #3
@@ -1333,25 +1332,26 @@ define void @test_shl_i1024(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    cmp x9, #15
 ; GISEL-NEXT:    csel x13, xzr, x13, eq
 ; GISEL-NEXT:    cmp x8, #0
-; GISEL-NEXT:    lsl x26, x12, x14
+; GISEL-NEXT:    lsl x6, x12, x2
 ; GISEL-NEXT:    csel x11, x11, x13, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    str x11, [sp, #224] ; 8-byte Spill
-; GISEL-NEXT:    csel x11, xzr, x20, eq
+; GISEL-NEXT:    str x11, [sp, #208] ; 8-byte Spill
+; GISEL-NEXT:    csel x11, xzr, x3, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    orr x11, x26, x11
-; GISEL-NEXT:    lsr x15, x12, x2
-; GISEL-NEXT:    lsl x30, x10, x16
+; GISEL-NEXT:    orr x11, x6, x11
+; GISEL-NEXT:    lsl x14, x10, x2
+; GISEL-NEXT:    lsr x16, x10, x24
 ; GISEL-NEXT:    csel x11, x11, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    lsr x17, x10, x2
-; GISEL-NEXT:    csel x13, xzr, x3, eq
+; GISEL-NEXT:    mov x26, x6
+; GISEL-NEXT:    csel x13, xzr, x17, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    orr x13, x6, x13
+; GISEL-NEXT:    orr x13, x28, x13
 ; GISEL-NEXT:    csel x11, x13, x11, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    csel x11, x0, x11, eq
+; GISEL-NEXT:    csel x11, x15, x11, eq
 ; GISEL-NEXT:    cmp x9, #3
+; GISEL-NEXT:    lsr x15, x12, x24
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
 ; GISEL-NEXT:    cmp x9, #4
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
@@ -1380,23 +1380,23 @@ define void @test_shl_i1024(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    cmp x8, #0
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    str x11, [sp, #216] ; 8-byte Spill
+; GISEL-NEXT:    str x11, [sp, #200] ; 8-byte Spill
 ; GISEL-NEXT:    csel x11, xzr, x15, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    orr x11, x30, x11
+; GISEL-NEXT:    orr x11, x14, x11
 ; GISEL-NEXT:    csel x11, x11, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x20, eq
+; GISEL-NEXT:    csel x12, xzr, x3, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    orr x12, x26, x12
+; GISEL-NEXT:    orr x12, x6, x12
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x3, eq
+; GISEL-NEXT:    csel x12, xzr, x17, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    orr x12, x6, x12
+; GISEL-NEXT:    orr x12, x28, x12
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    csel x11, x0, x11, eq
+; GISEL-NEXT:    csel x11, x23, x11, eq
 ; GISEL-NEXT:    cmp x9, #4
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
 ; GISEL-NEXT:    cmp x9, #5
@@ -1421,38 +1421,42 @@ define void @test_shl_i1024(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    ldp x12, x11, [x1, #32]
 ; GISEL-NEXT:    csel x13, xzr, x13, eq
 ; GISEL-NEXT:    cmp x9, #15
+; GISEL-NEXT:    mov x1, x17
 ; GISEL-NEXT:    csel x13, xzr, x13, eq
 ; GISEL-NEXT:    cmp x8, #0
-; GISEL-NEXT:    lsl x0, x12, x16
+; GISEL-NEXT:    mov x22, x1
+; GISEL-NEXT:    lsl x0, x12, x2
 ; GISEL-NEXT:    csel x10, x10, x13, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    str x10, [sp, #208] ; 8-byte Spill
-; GISEL-NEXT:    csel x10, xzr, x17, eq
+; GISEL-NEXT:    str x10, [sp, #192] ; 8-byte Spill
+; GISEL-NEXT:    csel x10, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #0
 ; GISEL-NEXT:    orr x10, x0, x10
-; GISEL-NEXT:    lsr x4, x12, x2
-; GISEL-NEXT:    lsl x19, x11, x16
+; GISEL-NEXT:    lsr x2, x12, x24
+; GISEL-NEXT:    lsl x27, x11, x4
 ; GISEL-NEXT:    csel x10, x10, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    mov x16, x15
+; GISEL-NEXT:    str x0, [sp, #248] ; 8-byte Spill
 ; GISEL-NEXT:    csel x13, xzr, x15, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    str x4, [sp, #248] ; 8-byte Spill
-; GISEL-NEXT:    orr x13, x30, x13
-; GISEL-NEXT:    str x0, [sp, #48] ; 8-byte Spill
+; GISEL-NEXT:    str x2, [sp, #224] ; 8-byte Spill
+; GISEL-NEXT:    orr x13, x14, x13
 ; GISEL-NEXT:    csel x10, x13, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x20, eq
+; GISEL-NEXT:    csel x13, xzr, x3, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    orr x13, x26, x13
+; GISEL-NEXT:    orr x13, x6, x13
 ; GISEL-NEXT:    csel x10, x13, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x3, eq
+; GISEL-NEXT:    csel x13, xzr, x17, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    orr x13, x6, x13
+; GISEL-NEXT:    mov x17, x3
+; GISEL-NEXT:    orr x13, x28, x13
+; GISEL-NEXT:    mov x7, x17
 ; GISEL-NEXT:    csel x10, x13, x10, eq
 ; GISEL-NEXT:    cmp x9, #4
-; GISEL-NEXT:    csel x10, x24, x10, eq
+; GISEL-NEXT:    str x7, [sp, #16] ; 8-byte Spill
+; GISEL-NEXT:    csel x10, x23, x10, eq
 ; GISEL-NEXT:    cmp x9, #5
 ; GISEL-NEXT:    csel x10, xzr, x10, eq
 ; GISEL-NEXT:    cmp x9, #6
@@ -1478,35 +1482,35 @@ define void @test_shl_i1024(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    cmp x8, #0
 ; GISEL-NEXT:    csel x10, x12, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    str x10, [sp, #200] ; 8-byte Spill
-; GISEL-NEXT:    csel x10, xzr, x4, eq
+; GISEL-NEXT:    str x10, [sp, #184] ; 8-byte Spill
+; GISEL-NEXT:    csel x10, xzr, x2, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    orr x10, x19, x10
+; GISEL-NEXT:    orr x10, x27, x10
 ; GISEL-NEXT:    csel x10, x10, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x17, eq
+; GISEL-NEXT:    csel x12, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #1
 ; GISEL-NEXT:    orr x12, x0, x12
 ; GISEL-NEXT:    csel x10, x12, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x12, xzr, x15, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    and x15, x8, #0x3f
-; GISEL-NEXT:    orr x12, x30, x12
+; GISEL-NEXT:    orr x12, x14, x12
 ; GISEL-NEXT:    csel x10, x12, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x20, eq
+; GISEL-NEXT:    csel x12, xzr, x3, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    orr x12, x26, x12
+; GISEL-NEXT:    lsr x3, x11, x24
+; GISEL-NEXT:    orr x12, x6, x12
 ; GISEL-NEXT:    csel x10, x12, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x3, eq
+; GISEL-NEXT:    str x3, [sp, #328] ; 8-byte Spill
+; GISEL-NEXT:    csel x12, xzr, x1, eq
 ; GISEL-NEXT:    cmp x9, #4
-; GISEL-NEXT:    lsr x3, x11, x2
-; GISEL-NEXT:    orr x12, x6, x12
+; GISEL-NEXT:    orr x12, x28, x12
 ; GISEL-NEXT:    csel x10, x12, x10, eq
 ; GISEL-NEXT:    cmp x9, #5
-; GISEL-NEXT:    csel x10, x24, x10, eq
+; GISEL-NEXT:    csel x10, x23, x10, eq
 ; GISEL-NEXT:    cmp x9, #6
 ; GISEL-NEXT:    csel x10, xzr, x10, eq
 ; GISEL-NEXT:    cmp x9, #7
@@ -1524,56 +1528,56 @@ define void @test_shl_i1024(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    cmp x9, #13
 ; GISEL-NEXT:    csel x13, xzr, x10, eq
 ; GISEL-NEXT:    cmp x9, #14
-; GISEL-NEXT:    ldp x12, x10, [x1, #48]
+; GISEL-NEXT:    ldp x12, x10, [x19, #48]
 ; GISEL-NEXT:    csel x13, xzr, x13, eq
 ; GISEL-NEXT:    cmp x9, #15
+; GISEL-NEXT:    mov x19, x17
 ; GISEL-NEXT:    csel x13, xzr, x13, eq
 ; GISEL-NEXT:    cmp x8, #0
-; GISEL-NEXT:    lsl x22, x12, x15
+; GISEL-NEXT:    lsl x4, x12, x4
 ; GISEL-NEXT:    csel x11, x11, x13, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    str x11, [sp, #192] ; 8-byte Spill
+; GISEL-NEXT:    str x11, [sp, #176] ; 8-byte Spill
 ; GISEL-NEXT:    csel x11, xzr, x3, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    orr x11, x22, x11
-; GISEL-NEXT:    lsl x5, x10, x15
-; GISEL-NEXT:    lsr x27, x10, x2
+; GISEL-NEXT:    orr x11, x4, x11
+; GISEL-NEXT:    lsl x30, x10, x5
 ; GISEL-NEXT:    csel x11, x11, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x4, eq
+; GISEL-NEXT:    csel x13, xzr, x2, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    mov x25, x27
-; GISEL-NEXT:    orr x13, x19, x13
-; GISEL-NEXT:    mov x14, x5
-; GISEL-NEXT:    str x27, [sp, #328] ; 8-byte Spill
+; GISEL-NEXT:    str x30, [sp, #232] ; 8-byte Spill
+; GISEL-NEXT:    orr x13, x27, x13
 ; GISEL-NEXT:    csel x11, x13, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x17, eq
+; GISEL-NEXT:    csel x13, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #2
 ; GISEL-NEXT:    orr x13, x0, x13
 ; GISEL-NEXT:    csel x11, x13, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x16, eq
+; GISEL-NEXT:    csel x13, xzr, x15, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    orr x13, x30, x13
+; GISEL-NEXT:    orr x13, x14, x13
 ; GISEL-NEXT:    csel x11, x13, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x20, eq
+; GISEL-NEXT:    csel x13, xzr, x17, eq
 ; GISEL-NEXT:    cmp x9, #4
-; GISEL-NEXT:    orr x13, x26, x13
+; GISEL-NEXT:    mov x17, x27
+; GISEL-NEXT:    orr x13, x6, x13
+; GISEL-NEXT:    mov x25, x17
+; GISEL-NEXT:    str x17, [sp, #288] ; 8-byte Spill
 ; GISEL-NEXT:    csel x11, x13, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x7, eq
+; GISEL-NEXT:    csel x13, xzr, x1, eq
 ; GISEL-NEXT:    cmp x9, #5
-; GISEL-NEXT:    orr x13, x6, x13
+; GISEL-NEXT:    orr x13, x28, x13
 ; GISEL-NEXT:    csel x11, x13, x11, eq
 ; GISEL-NEXT:    cmp x9, #6
-; GISEL-NEXT:    lsr x13, x12, x2
-; GISEL-NEXT:    csel x11, x24, x11, eq
+; GISEL-NEXT:    lsr x13, x12, x24
+; GISEL-NEXT:    csel x11, x23, x11, eq
 ; GISEL-NEXT:    cmp x9, #7
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
 ; GISEL-NEXT:    cmp x9, #8
-; GISEL-NEXT:    mov x15, x13
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
 ; GISEL-NEXT:    cmp x9, #9
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
@@ -1592,43 +1596,43 @@ define void @test_shl_i1024(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    cmp x8, #0
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    str x11, [sp, #184] ; 8-byte Spill
+; GISEL-NEXT:    str x11, [sp, #168] ; 8-byte Spill
 ; GISEL-NEXT:    csel x11, xzr, x13, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    orr x11, x5, x11
+; GISEL-NEXT:    orr x11, x30, x11
 ; GISEL-NEXT:    csel x11, x11, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x12, xzr, x3, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    orr x12, x22, x12
+; GISEL-NEXT:    orr x12, x4, x12
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x4, eq
+; GISEL-NEXT:    csel x12, xzr, x2, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    orr x12, x19, x12
+; GISEL-NEXT:    orr x12, x27, x12
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x17, eq
+; GISEL-NEXT:    csel x12, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #3
 ; GISEL-NEXT:    orr x12, x0, x12
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x16, eq
+; GISEL-NEXT:    csel x12, xzr, x15, eq
 ; GISEL-NEXT:    cmp x9, #4
-; GISEL-NEXT:    orr x12, x30, x12
+; GISEL-NEXT:    orr x12, x14, x12
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x20, eq
+; GISEL-NEXT:    csel x12, xzr, x19, eq
 ; GISEL-NEXT:    cmp x9, #5
-; GISEL-NEXT:    orr x12, x26, x12
+; GISEL-NEXT:    orr x12, x6, x12
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x7, eq
+; GISEL-NEXT:    csel x12, xzr, x1, eq
 ; GISEL-NEXT:    cmp x9, #6
-; GISEL-NEXT:    orr x12, x6, x12
+; GISEL-NEXT:    orr x12, x28, x12
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    cmp x9, #7
-; GISEL-NEXT:    csel x11, x24, x11, eq
+; GISEL-NEXT:    csel x11, x23, x11, eq
 ; GISEL-NEXT:    cmp x9, #8
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
 ; GISEL-NEXT:    cmp x9, #9
@@ -1643,65 +1647,73 @@ define void @test_shl_i1024(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
 ; GISEL-NEXT:    cmp x9, #14
 ; GISEL-NEXT:    csel x12, xzr, x11, eq
-; GISEL-NEXT:    ldp x11, x1, [x1, #64]
 ; GISEL-NEXT:    cmp x9, #15
+; GISEL-NEXT:    ldp x11, x19, [x20, #64]
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x8, #0
+; GISEL-NEXT:    mov x20, x26
 ; GISEL-NEXT:    csel x12, x10, x12, eq
+; GISEL-NEXT:    lsr x10, x10, x24
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    lsl x23, x11, x21
-; GISEL-NEXT:    str x12, [sp, #176] ; 8-byte Spill
-; GISEL-NEXT:    csel x12, xzr, x27, eq
+; GISEL-NEXT:    lsl x6, x11, x5
+; GISEL-NEXT:    str x12, [sp, #160] ; 8-byte Spill
+; GISEL-NEXT:    csel x12, xzr, x10, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    orr x12, x23, x12
-; GISEL-NEXT:    lsr x21, x11, x2
-; GISEL-NEXT:    str x23, [sp, #288] ; 8-byte Spill
+; GISEL-NEXT:    str x10, [sp, #256] ; 8-byte Spill
+; GISEL-NEXT:    orr x12, x6, x12
+; GISEL-NEXT:    mov x5, x6
+; GISEL-NEXT:    str x6, [sp, #240] ; 8-byte Spill
 ; GISEL-NEXT:    csel x12, x12, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
+; GISEL-NEXT:    mov x6, x13
 ; GISEL-NEXT:    csel x13, xzr, x13, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    orr x13, x5, x13
+; GISEL-NEXT:    str x6, [sp, #336] ; 8-byte Spill
+; GISEL-NEXT:    orr x13, x30, x13
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x13, xzr, x3, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    orr x13, x22, x13
+; GISEL-NEXT:    orr x13, x4, x13
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x4, eq
+; GISEL-NEXT:    csel x13, xzr, x2, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    orr x13, x19, x13
+; GISEL-NEXT:    orr x13, x27, x13
+; GISEL-NEXT:    lsr x27, x11, x24
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x17, eq
+; GISEL-NEXT:    csel x13, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #4
+; GISEL-NEXT:    str x27, [sp, #264] ; 8-byte Spill
 ; GISEL-NEXT:    orr x13, x0, x13
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x16, eq
+; GISEL-NEXT:    csel x13, xzr, x15, eq
 ; GISEL-NEXT:    cmp x9, #5
-; GISEL-NEXT:    orr x13, x30, x13
+; GISEL-NEXT:    orr x13, x14, x13
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x20, eq
+; GISEL-NEXT:    csel x13, xzr, x7, eq
 ; GISEL-NEXT:    cmp x9, #6
 ; GISEL-NEXT:    orr x13, x26, x13
+; GISEL-NEXT:    mov x26, x21
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x7, eq
+; GISEL-NEXT:    str x26, [sp, #64] ; 8-byte Spill
+; GISEL-NEXT:    csel x13, xzr, x1, eq
 ; GISEL-NEXT:    cmp x9, #7
-; GISEL-NEXT:    orr x13, x6, x13
+; GISEL-NEXT:    lsl x1, x19, x21
+; GISEL-NEXT:    orr x13, x28, x13
+; GISEL-NEXT:    mov x21, x6
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    cmp x9, #8
-; GISEL-NEXT:    and x13, x8, #0x3f
-; GISEL-NEXT:    csel x12, x24, x12, eq
+; GISEL-NEXT:    csel x12, x23, x12, eq
 ; GISEL-NEXT:    cmp x9, #9
-; GISEL-NEXT:    lsl x10, x1, x13
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #10
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #11
-; GISEL-NEXT:    stp x10, x15, [sp, #312] ; 16-byte Folded Spill
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #12
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
@@ -1714,69 +1726,72 @@ define void @test_shl_i1024(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    cmp x8, #0
 ; GISEL-NEXT:    csel x11, x11, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    str x11, [sp, #168] ; 8-byte Spill
-; GISEL-NEXT:    csel x11, xzr, x21, eq
+; GISEL-NEXT:    str x11, [sp, #152] ; 8-byte Spill
+; GISEL-NEXT:    csel x11, xzr, x27, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    orr x11, x10, x11
-; GISEL-NEXT:    mov x10, x23
+; GISEL-NEXT:    orr x11, x1, x11
 ; GISEL-NEXT:    csel x11, x11, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x27, eq
+; GISEL-NEXT:    csel x12, xzr, x10, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    mov x27, x24
-; GISEL-NEXT:    orr x12, x23, x12
-; GISEL-NEXT:    mov x23, x15
+; GISEL-NEXT:    orr x12, x5, x12
+; GISEL-NEXT:    mov x5, x22
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x15, eq
+; GISEL-NEXT:    str x5, [sp, #40] ; 8-byte Spill
+; GISEL-NEXT:    csel x12, xzr, x6, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    mov x15, x22
-; GISEL-NEXT:    orr x12, x5, x12
-; GISEL-NEXT:    mov x5, x3
+; GISEL-NEXT:    orr x12, x30, x12
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    stp x14, x5, [sp, #256] ; 16-byte Folded Spill
 ; GISEL-NEXT:    csel x12, xzr, x3, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    mov x5, x4
-; GISEL-NEXT:    orr x12, x22, x12
-; GISEL-NEXT:    lsr x22, x1, x2
+; GISEL-NEXT:    mov x3, x4
+; GISEL-NEXT:    orr x12, x4, x12
+; GISEL-NEXT:    mov x4, x24
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x4, eq
+; GISEL-NEXT:    csel x12, xzr, x2, eq
 ; GISEL-NEXT:    cmp x9, #4
-; GISEL-NEXT:    str x22, [sp, #240] ; 8-byte Spill
-; GISEL-NEXT:    orr x12, x19, x12
+; GISEL-NEXT:    mov x2, x20
+; GISEL-NEXT:    orr x12, x17, x12
+; GISEL-NEXT:    mov x17, x16
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x17, eq
+; GISEL-NEXT:    str x17, [sp, #48] ; 8-byte Spill
+; GISEL-NEXT:    csel x12, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #5
+; GISEL-NEXT:    mov x16, x15
 ; GISEL-NEXT:    orr x12, x0, x12
+; GISEL-NEXT:    mov x0, x30
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x16, eq
+; GISEL-NEXT:    csel x12, xzr, x15, eq
 ; GISEL-NEXT:    cmp x9, #6
-; GISEL-NEXT:    orr x12, x30, x12
+; GISEL-NEXT:    ldr x15, [sp, #344] ; 8-byte Reload
+; GISEL-NEXT:    orr x12, x14, x12
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x20, eq
+; GISEL-NEXT:    csel x12, xzr, x7, eq
 ; GISEL-NEXT:    cmp x9, #7
-; GISEL-NEXT:    orr x12, x26, x12
+; GISEL-NEXT:    ldr x7, [sp, #224] ; 8-byte Reload
+; GISEL-NEXT:    orr x12, x20, x12
+; GISEL-NEXT:    mov x20, x23
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x7, eq
+; GISEL-NEXT:    str x20, [sp, #56] ; 8-byte Spill
+; GISEL-NEXT:    csel x12, xzr, x22, eq
 ; GISEL-NEXT:    cmp x9, #8
-; GISEL-NEXT:    mov x7, x14
-; GISEL-NEXT:    orr x12, x6, x12
-; GISEL-NEXT:    mov x6, x28
+; GISEL-NEXT:    mov x22, x3
+; GISEL-NEXT:    orr x12, x28, x12
+; GISEL-NEXT:    str x22, [sp, #32] ; 8-byte Spill
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    cmp x9, #9
-; GISEL-NEXT:    csel x11, x24, x11, eq
+; GISEL-NEXT:    csel x11, x23, x11, eq
 ; GISEL-NEXT:    cmp x9, #10
-; GISEL-NEXT:    ldr x24, [x6, #88]
+; GISEL-NEXT:    ldr x23, [sp, #240] ; 8-byte Reload
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
 ; GISEL-NEXT:    cmp x9, #11
-; GISEL-NEXT:    ldr x6, [sp, #272] ; 8-byte Reload
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
 ; GISEL-NEXT:    cmp x9, #12
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
@@ -1786,165 +1801,165 @@ define void @test_shl_i1024(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
 ; GISEL-NEXT:    cmp x9, #15
 ; GISEL-NEXT:    csel x12, xzr, x11, eq
-; GISEL-NEXT:    ldr x11, [x28, #80]
+; GISEL-NEXT:    ldp x11, x6, [x15, #80]
 ; GISEL-NEXT:    cmp x8, #0
-; GISEL-NEXT:    csel x12, x1, x12, eq
-; GISEL-NEXT:    mov x28, x2
+; GISEL-NEXT:    ldr x15, [sp, #328] ; 8-byte Reload
+; GISEL-NEXT:    csel x12, x19, x12, eq
+; GISEL-NEXT:    lsr x19, x19, x24
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    lsl x2, x11, x13
-; GISEL-NEXT:    str x12, [sp, #160] ; 8-byte Spill
-; GISEL-NEXT:    csel x12, xzr, x22, eq
+; GISEL-NEXT:    lsl x24, x11, x26
+; GISEL-NEXT:    str x12, [sp, #144] ; 8-byte Spill
+; GISEL-NEXT:    csel x12, xzr, x19, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    ldr x1, [sp, #312] ; 8-byte Reload
-; GISEL-NEXT:    str x28, [sp, #16] ; 8-byte Spill
-; GISEL-NEXT:    orr x12, x2, x12
-; GISEL-NEXT:    str x2, [sp, #280] ; 8-byte Spill
+; GISEL-NEXT:    str x19, [sp, #72] ; 8-byte Spill
+; GISEL-NEXT:    orr x12, x24, x12
+; GISEL-NEXT:    stp x1, x24, [sp, #272] ; 16-byte Folded Spill
 ; GISEL-NEXT:    csel x12, x12, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x21, eq
+; GISEL-NEXT:    csel x13, xzr, x27, eq
 ; GISEL-NEXT:    cmp x9, #1
 ; GISEL-NEXT:    orr x13, x1, x13
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x25, eq
+; GISEL-NEXT:    csel x13, xzr, x10, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    mov x25, x16
-; GISEL-NEXT:    orr x13, x10, x13
-; GISEL-NEXT:    mov x10, x30
-; GISEL-NEXT:    str x25, [sp, #80] ; 8-byte Spill
+; GISEL-NEXT:    mov x10, x2
+; GISEL-NEXT:    orr x13, x23, x13
+; GISEL-NEXT:    str x10, [sp, #88] ; 8-byte Spill
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x23, eq
+; GISEL-NEXT:    csel x13, xzr, x21, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    mov x23, x3
-; GISEL-NEXT:    orr x13, x14, x13
-; GISEL-NEXT:    mov x14, x17
+; GISEL-NEXT:    mov x21, x14
+; GISEL-NEXT:    orr x13, x30, x13
+; GISEL-NEXT:    ldr x30, [sp, #248] ; 8-byte Reload
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    stp x19, x14, [sp, #64] ; 16-byte Folded Spill
-; GISEL-NEXT:    csel x13, xzr, x3, eq
+; GISEL-NEXT:    csel x13, xzr, x15, eq
 ; GISEL-NEXT:    cmp x9, #4
-; GISEL-NEXT:    mov x3, x21
-; GISEL-NEXT:    orr x13, x15, x13
-; GISEL-NEXT:    str x3, [sp, #32] ; 8-byte Spill
+; GISEL-NEXT:    orr x13, x3, x13
+; GISEL-NEXT:    lsr x3, x11, x4
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x4, eq
+; GISEL-NEXT:    csel x13, xzr, x7, eq
 ; GISEL-NEXT:    cmp x9, #5
-; GISEL-NEXT:    mov x4, x0
-; GISEL-NEXT:    orr x13, x19, x13
+; GISEL-NEXT:    orr x13, x25, x13
+; GISEL-NEXT:    mov x25, x24
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x13, xzr, x17, eq
 ; GISEL-NEXT:    cmp x9, #6
-; GISEL-NEXT:    mov x17, x27
-; GISEL-NEXT:    orr x13, x0, x13
-; GISEL-NEXT:    ldr x0, [sp, #24] ; 8-byte Reload
+; GISEL-NEXT:    orr x13, x30, x13
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x13, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #7
-; GISEL-NEXT:    orr x13, x30, x13
-; GISEL-NEXT:    ldp x30, x16, [sp, #320] ; 16-byte Folded Reload
+; GISEL-NEXT:    orr x13, x14, x13
+; GISEL-NEXT:    ldr x14, [sp, #16] ; 8-byte Reload
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x20, eq
+; GISEL-NEXT:    csel x13, xzr, x14, eq
 ; GISEL-NEXT:    cmp x9, #8
-; GISEL-NEXT:    orr x13, x26, x13
+; GISEL-NEXT:    orr x13, x2, x13
+; GISEL-NEXT:    mov x2, x6
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x6, eq
+; GISEL-NEXT:    csel x13, xzr, x5, eq
 ; GISEL-NEXT:    cmp x9, #9
-; GISEL-NEXT:    orr x13, x0, x13
+; GISEL-NEXT:    orr x13, x28, x13
+; GISEL-NEXT:    mov x28, x19
 ; GISEL-NEXT:    csel x12, x13, x12, eq
 ; GISEL-NEXT:    cmp x9, #10
-; GISEL-NEXT:    lsr x13, x11, x28
-; GISEL-NEXT:    csel x12, x27, x12, eq
+; GISEL-NEXT:    mov x13, x20
+; GISEL-NEXT:    csel x12, x20, x12, eq
 ; GISEL-NEXT:    cmp x9, #11
+; GISEL-NEXT:    mov x20, x4
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #12
-; GISEL-NEXT:    str x13, [sp, #96] ; 8-byte Spill
+; GISEL-NEXT:    lsl x4, x6, x26
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #13
+; GISEL-NEXT:    ldr x6, [sp, #336] ; 8-byte Reload
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #14
+; GISEL-NEXT:    stp x4, x3, [sp, #296] ; 16-byte Folded Spill
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #15
 ; GISEL-NEXT:    csel x12, xzr, x12, eq
 ; GISEL-NEXT:    cmp x8, #0
 ; GISEL-NEXT:    csel x11, x11, x12, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    str x11, [sp, #152] ; 8-byte Spill
-; GISEL-NEXT:    and x11, x8, #0x3f
-; GISEL-NEXT:    lsl x27, x24, x11
-; GISEL-NEXT:    csel x11, xzr, x13, eq
+; GISEL-NEXT:    str x11, [sp, #128] ; 8-byte Spill
+; GISEL-NEXT:    csel x11, xzr, x3, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    orr x11, x27, x11
-; GISEL-NEXT:    str x27, [sp, #56] ; 8-byte Spill
+; GISEL-NEXT:    orr x11, x4, x11
+; GISEL-NEXT:    mov x3, x15
 ; GISEL-NEXT:    csel x11, x11, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x22, eq
+; GISEL-NEXT:    csel x12, xzr, x19, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    mov x22, x2
-; GISEL-NEXT:    orr x12, x2, x12
-; GISEL-NEXT:    mov x2, x14
+; GISEL-NEXT:    ldr x19, [sp, #256] ; 8-byte Reload
+; GISEL-NEXT:    orr x12, x24, x12
+; GISEL-NEXT:    ldr x24, [sp, #312] ; 8-byte Reload
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x21, eq
+; GISEL-NEXT:    csel x12, xzr, x27, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    ldr x21, [sp, #288] ; 8-byte Reload
+; GISEL-NEXT:    mov x27, x1
 ; GISEL-NEXT:    orr x12, x1, x12
-; GISEL-NEXT:    mov x1, x27
+; GISEL-NEXT:    ldr x1, [sp, #288] ; 8-byte Reload
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x16, eq
+; GISEL-NEXT:    csel x12, xzr, x19, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    orr x12, x21, x12
+; GISEL-NEXT:    orr x12, x23, x12
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x30, eq
+; GISEL-NEXT:    csel x12, xzr, x6, eq
 ; GISEL-NEXT:    cmp x9, #4
-; GISEL-NEXT:    orr x12, x7, x12
-; GISEL-NEXT:    mov x7, x15
+; GISEL-NEXT:    orr x12, x0, x12
+; GISEL-NEXT:    mov x0, x10
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    str x7, [sp, #40] ; 8-byte Spill
-; GISEL-NEXT:    csel x12, xzr, x23, eq
+; GISEL-NEXT:    csel x12, xzr, x15, eq
 ; GISEL-NEXT:    cmp x9, #5
-; GISEL-NEXT:    orr x12, x15, x12
+; GISEL-NEXT:    mov x15, x7
+; GISEL-NEXT:    orr x12, x22, x12
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x5, eq
+; GISEL-NEXT:    csel x12, xzr, x7, eq
 ; GISEL-NEXT:    cmp x9, #6
-; GISEL-NEXT:    mov x5, x19
-; GISEL-NEXT:    orr x12, x19, x12
-; GISEL-NEXT:    mov x19, x7
+; GISEL-NEXT:    mov x7, x26
+; GISEL-NEXT:    orr x12, x1, x12
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x14, eq
+; GISEL-NEXT:    csel x12, xzr, x17, eq
 ; GISEL-NEXT:    cmp x9, #7
-; GISEL-NEXT:    lsr x14, x24, x28
-; GISEL-NEXT:    orr x12, x4, x12
-; GISEL-NEXT:    mov x4, x10
+; GISEL-NEXT:    mov x17, x23
+; GISEL-NEXT:    orr x12, x30, x12
+; GISEL-NEXT:    mov x30, x21
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x25, eq
+; GISEL-NEXT:    csel x12, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #8
-; GISEL-NEXT:    orr x12, x10, x12
-; GISEL-NEXT:    ldr x10, [sp, #304] ; 8-byte Reload
+; GISEL-NEXT:    orr x12, x21, x12
+; GISEL-NEXT:    mov x21, x14
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x20, eq
+; GISEL-NEXT:    csel x12, xzr, x14, eq
 ; GISEL-NEXT:    cmp x9, #9
-; GISEL-NEXT:    orr x12, x26, x12
+; GISEL-NEXT:    orr x12, x10, x12
+; GISEL-NEXT:    ldr x10, [sp, #344] ; 8-byte Reload
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x12, xzr, x6, eq
+; GISEL-NEXT:    csel x12, xzr, x5, eq
 ; GISEL-NEXT:    cmp x9, #10
-; GISEL-NEXT:    orr x12, x0, x12
+; GISEL-NEXT:    mov x5, x20
+; GISEL-NEXT:    orr x12, x24, x12
+; GISEL-NEXT:    str x5, [sp, #8] ; 8-byte Spill
 ; GISEL-NEXT:    csel x11, x12, x11, eq
 ; GISEL-NEXT:    cmp x9, #11
-; GISEL-NEXT:    csel x11, x17, x11, eq
+; GISEL-NEXT:    csel x11, x13, x11, eq
 ; GISEL-NEXT:    cmp x9, #12
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
 ; GISEL-NEXT:    cmp x9, #13
@@ -1953,395 +1968,398 @@ define void @test_shl_i1024(ptr %result, ptr %input, i32 %shift) {
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
 ; GISEL-NEXT:    cmp x9, #15
 ; GISEL-NEXT:    csel x12, xzr, x11, eq
-; GISEL-NEXT:    ldp x11, x6, [x10, #96]
 ; GISEL-NEXT:    cmp x8, #0
-; GISEL-NEXT:    and x10, x8, #0x3f
-; GISEL-NEXT:    csel x12, x24, x12, eq
-; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    ldr x24, [sp, #248] ; 8-byte Reload
-; GISEL-NEXT:    lsl x15, x11, x10
-; GISEL-NEXT:    csel x10, xzr, x14, eq
+; GISEL-NEXT:    ldp x11, x14, [x10, #96]
+; GISEL-NEXT:    csel x12, x2, x12, eq
+; GISEL-NEXT:    str x12, [sp, #120] ; 8-byte Spill
+; GISEL-NEXT:    lsr x12, x2, x20
+; GISEL-NEXT:    tst x8, #0x3f
+; GISEL-NEXT:    ldr x2, [sp, #48] ; 8-byte Reload
+; GISEL-NEXT:    mov x20, x19
+; GISEL-NEXT:    lsl x13, x11, x26
+; GISEL-NEXT:    csel x10, xzr, x12, eq
+; GISEL-NEXT:    mov x26, x12
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    str x12, [sp, #136] ; 8-byte Spill
-; GISEL-NEXT:    ldr x12, [sp, #312] ; 8-byte Reload
-; GISEL-NEXT:    orr x10, x15, x10
-; GISEL-NEXT:    str x15, [sp, #296] ; 8-byte Spill
-; GISEL-NEXT:    mov x15, x13
+; GISEL-NEXT:    ldr x12, [sp, #304] ; 8-byte Reload
+; GISEL-NEXT:    str x14, [sp, #24] ; 8-byte Spill
+; GISEL-NEXT:    orr x10, x13, x10
+; GISEL-NEXT:    str x13, [sp, #80] ; 8-byte Spill
 ; GISEL-NEXT:    csel x10, x10, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x13, eq
+; GISEL-NEXT:    csel x13, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    orr x13, x27, x13
-; GISEL-NEXT:    ldr x27, [sp, #240] ; 8-byte Reload
+; GISEL-NEXT:    orr x13, x4, x13
+; GISEL-NEXT:    ldr x4, [sp, #264] ; 8-byte Reload
 ; GISEL-NEXT:    csel x10, x13, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x27, eq
+; GISEL-NEXT:    csel x13, xzr, x28, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    orr x13, x22, x13
-; GISEL-NEXT:    ldr x22, [sp, #272] ; 8-byte Reload
+; GISEL-NEXT:    orr x13, x25, x13
+; GISEL-NEXT:    ldr x25, [sp, #232] ; 8-byte Reload
 ; GISEL-NEXT:    csel x10, x13, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x3, eq
+; GISEL-NEXT:    csel x13, xzr, x4, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    orr x13, x12, x13
+; GISEL-NEXT:    orr x13, x27, x13
+; GISEL-NEXT:    mov x27, x22
 ; GISEL-NEXT:    csel x10, x13, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x16, eq
+; GISEL-NEXT:    csel x13, xzr, x19, eq
 ; GISEL-NEXT:    cmp x9, #4
-; GISEL-NEXT:    mov x16, x17
-; GISEL-NEXT:    orr x13, x21, x13
-; GISEL-NEXT:    ldp x23, x21, [sp, #256] ; 16-byte Folded Reload
+; GISEL-NEXT:    mov x19, x15
+; GISEL-NEXT:    orr x13, x23, x13
+; GISEL-NEXT:    mov x23, x21
 ; GISEL-NEXT:    csel x10, x13, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x30, eq
+; GISEL-NEXT:    csel x13, xzr, x6, eq
 ; GISEL-NEXT:    cmp x9, #5
-; GISEL-NEXT:    mov x30, x0
-; GISEL-NEXT:    orr x13, x23, x13
+; GISEL-NEXT:    mov x6, x16
+; GISEL-NEXT:    orr x13, x25, x13
 ; GISEL-NEXT:    csel x10, x13, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x21, eq
+; GISEL-NEXT:    csel x13, xzr, x3, eq
 ; GISEL-NEXT:    cmp x9, #6
-; GISEL-NEXT:    orr x13, x7, x13
-; GISEL-NEXT:    mov x7, x14
+; GISEL-NEXT:    ldr x3, [sp, #248] ; 8-byte Reload
+; GISEL-NEXT:    orr x13, x22, x13
+; GISEL-NEXT:    mov x22, x30
 ; GISEL-NEXT:    csel x10, x13, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x24, eq
+; GISEL-NEXT:    csel x13, xzr, x15, eq
 ; GISEL-NEXT:    cmp x9, #7
-; GISEL-NEXT:    orr x13, x5, x13
-; GISEL-NEXT:    ldr x5, [sp, #48] ; 8-byte Reload
+; GISEL-NEXT:    orr x13, x1, x13
+; GISEL-NEXT:    mov x1, x5
 ; GISEL-NEXT:    csel x10, x13, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x13, xzr, x2, eq
 ; GISEL-NEXT:    cmp x9, #8
-; GISEL-NEXT:    ldr x2, [sp, #296] ; 8-byte Reload
-; GISEL-NEXT:    orr x13, x5, x13
+; GISEL-NEXT:    orr x13, x3, x13
 ; GISEL-NEXT:    csel x10, x13, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x25, eq
+; GISEL-NEXT:    csel x13, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #9
-; GISEL-NEXT:    mov x25, x6
-; GISEL-NEXT:    orr x13, x4, x13
+; GISEL-NEXT:    orr x13, x30, x13
+; GISEL-NEXT:    ldp x15, x16, [sp, #272] ; 16-byte Folded Reload
 ; GISEL-NEXT:    csel x10, x13, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x20, eq
+; GISEL-NEXT:    mov x30, x24
+; GISEL-NEXT:    csel x13, xzr, x21, eq
 ; GISEL-NEXT:    cmp x9, #10
-; GISEL-NEXT:    orr x13, x26, x13
+; GISEL-NEXT:    ldr x21, [sp, #40] ; 8-byte Reload
+; GISEL-NEXT:    orr x13, x0, x13
+; GISEL-NEXT:    ldr x0, [sp, #56] ; 8-byte Reload
 ; GISEL-NEXT:    csel x10, x13, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x13, xzr, x22, eq
+; GISEL-NEXT:    csel x13, xzr, x21, eq
 ; GISEL-NEXT:    cmp x9, #11
-; GISEL-NEXT:    orr x13, x0, x13
+; GISEL-NEXT:    orr x13, x24, x13
+; GISEL-NEXT:    mov x24, x6
 ; GISEL-NEXT:    csel x10, x13, x10, eq
 ; GISEL-NEXT:    cmp x9, #12
-; GISEL-NEXT:    lsr x13, x11, x28
-; GISEL-NEXT:    csel x10, x17, x10, eq
+; GISEL-NEXT:    lsr x13, x11, x5
+; GISEL-NEXT:    csel x10, x0, x10, eq
 ; GISEL-NEXT:    cmp x9, #13
-; GISEL-NEXT:    ldr x17, [sp, #80] ; 8-byte Reload
+; GISEL-NEXT:    ldr x5, [sp, #296] ; 8-byte Reload
 ; GISEL-NEXT:    csel x10, xzr, x10, eq
 ; GISEL-NEXT:    cmp x9, #14
-; GISEL-NEXT:    str x13, [sp, #104] ; 8-byte Spill
+; GISEL-NEXT:    str x13, [sp, #96] ; 8-byte Spill
 ; GISEL-NEXT:    csel x10, xzr, x10, eq
 ; GISEL-NEXT:    cmp x9, #15
 ; GISEL-NEXT:    csel x10, xzr, x10, eq
 ; GISEL-NEXT:    cmp x8, #0
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    str x10, [sp, #128] ; 8-byte Spill
-; GISEL-NEXT:    and x10, x8, #0x3f
-; GISEL-NEXT:    lsl x11, x6, x10
+; GISEL-NEXT:    lsl x11, x14, x7
+; GISEL-NEXT:    str x10, [sp, #112] ; 8-byte Spill
 ; GISEL-NEXT:    csel x10, xzr, x13, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    ldp x0, x13, [sp, #280] ; 16-byte Folded Reload
-; GISEL-NEXT:    mov x6, x16
 ; GISEL-NEXT:    orr x10, x11, x10
-; GISEL-NEXT:    str x11, [sp, #88] ; 8-byte Spill
+; GISEL-NEXT:    ldp x7, x28, [sp, #72] ; 16-byte Folded Reload
 ; GISEL-NEXT:    csel x10, x10, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x14, eq
+; GISEL-NEXT:    str x11, [sp, #320] ; 8-byte Spill
+; GISEL-NEXT:    csel x11, xzr, x26, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    orr x11, x2, x11
+; GISEL-NEXT:    orr x11, x28, x11
+; GISEL-NEXT:    ldp x13, x14, [sp, #328] ; 16-byte Folded Reload
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x15, eq
+; GISEL-NEXT:    csel x11, xzr, x12, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    mov x15, x3
-; GISEL-NEXT:    orr x11, x1, x11
+; GISEL-NEXT:    ldr x12, [sp, #288] ; 8-byte Reload
+; GISEL-NEXT:    orr x11, x5, x11
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x27, eq
+; GISEL-NEXT:    csel x11, xzr, x7, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    orr x11, x0, x11
+; GISEL-NEXT:    orr x11, x16, x11
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x3, eq
-; GISEL-NEXT:    ldp x14, x3, [sp, #320] ; 16-byte Folded Reload
+; GISEL-NEXT:    csel x11, xzr, x4, eq
 ; GISEL-NEXT:    cmp x9, #4
-; GISEL-NEXT:    orr x11, x12, x11
+; GISEL-NEXT:    ldr x4, [sp, #24] ; 8-byte Reload
+; GISEL-NEXT:    orr x11, x15, x11
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x3, eq
+; GISEL-NEXT:    csel x11, xzr, x20, eq
 ; GISEL-NEXT:    cmp x9, #5
-; GISEL-NEXT:    orr x11, x13, x11
+; GISEL-NEXT:    ldr x20, [sp, #304] ; 8-byte Reload
+; GISEL-NEXT:    orr x11, x17, x11
+; GISEL-NEXT:    ldr x17, [sp, #344] ; 8-byte Reload
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x11, xzr, x14, eq
 ; GISEL-NEXT:    cmp x9, #6
-; GISEL-NEXT:    orr x11, x23, x11
-; GISEL-NEXT:    mov x23, x5
+; GISEL-NEXT:    orr x11, x25, x11
+; GISEL-NEXT:    mov x25, x2
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x21, eq
+; GISEL-NEXT:    csel x11, xzr, x13, eq
 ; GISEL-NEXT:    cmp x9, #7
-; GISEL-NEXT:    mov x21, x4
-; GISEL-NEXT:    orr x11, x19, x11
-; GISEL-NEXT:    ldp x12, x19, [sp, #64] ; 16-byte Folded Reload
+; GISEL-NEXT:    orr x11, x27, x11
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x24, eq
+; GISEL-NEXT:    csel x11, xzr, x19, eq
 ; GISEL-NEXT:    cmp x9, #8
+; GISEL-NEXT:    ldr x19, [sp, #88] ; 8-byte Reload
 ; GISEL-NEXT:    orr x11, x12, x11
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x19, eq
+; GISEL-NEXT:    csel x11, xzr, x2, eq
 ; GISEL-NEXT:    cmp x9, #9
-; GISEL-NEXT:    orr x11, x5, x11
-; GISEL-NEXT:    mov x5, x30
+; GISEL-NEXT:    mov x2, x30
+; GISEL-NEXT:    orr x11, x3, x11
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x17, eq
+; GISEL-NEXT:    csel x11, xzr, x6, eq
 ; GISEL-NEXT:    cmp x9, #10
-; GISEL-NEXT:    orr x11, x4, x11
+; GISEL-NEXT:    ldr x6, [sp, #320] ; 8-byte Reload
+; GISEL-NEXT:    orr x11, x22, x11
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x20, eq
+; GISEL-NEXT:    csel x11, xzr, x23, eq
 ; GISEL-NEXT:    cmp x9, #11
-; GISEL-NEXT:    orr x11, x26, x11
+; GISEL-NEXT:    orr x11, x19, x11
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x22, eq
+; GISEL-NEXT:    csel x11, xzr, x21, eq
 ; GISEL-NEXT:    cmp x9, #12
 ; GISEL-NEXT:    orr x11, x30, x11
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    cmp x9, #13
-; GISEL-NEXT:    csel x10, x16, x10, eq
+; GISEL-NEXT:    csel x10, x0, x10, eq
 ; GISEL-NEXT:    cmp x9, #14
-; GISEL-NEXT:    ldr x16, [sp, #304] ; 8-byte Reload
 ; GISEL-NEXT:    csel x10, xzr, x10, eq
 ; GISEL-NEXT:    cmp x9, #15
 ; GISEL-NEXT:    csel x11, xzr, x10, eq
 ; GISEL-NEXT:    cmp x8, #0
-; GISEL-NEXT:    ldp x10, x4, [x16, #112]
-; GISEL-NEXT:    csel x11, x25, x11, eq
-; GISEL-NEXT:    str x11, [sp, #120] ; 8-byte Spill
-; GISEL-NEXT:    lsr x11, x25, x28
-; GISEL-NEXT:    and x16, x8, #0x3f
-; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    ldr x25, [sp, #88] ; 8-byte Reload
-; GISEL-NEXT:    lsl x24, x10, x16
-; GISEL-NEXT:    csel x1, xzr, x11, eq
+; GISEL-NEXT:    ldp x10, x17, [x17, #112]
+; GISEL-NEXT:    csel x11, x4, x11, eq
+; GISEL-NEXT:    str x11, [sp, #104] ; 8-byte Spill
+; GISEL-NEXT:    ldr x11, [sp, #64] ; 8-byte Reload
+; GISEL-NEXT:    lsr x4, x4, x1
+; GISEL-NEXT:    tst x8, #0x3f
+; GISEL-NEXT:    lsl x27, x10, x11
+; GISEL-NEXT:    csel x1, xzr, x4, eq
+; GISEL-NEXT:    str x4, [sp, #24] ; 8-byte Spill
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    ldp x16, x28, [sp, #96] ; 16-byte Folded Reload
-; GISEL-NEXT:    orr x1, x24, x1
+; GISEL-NEXT:    ldr x4, [sp, #96] ; 8-byte Reload
+; GISEL-NEXT:    orr x1, x27, x1
 ; GISEL-NEXT:    csel x1, x1, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x30, xzr, x28, eq
+; GISEL-NEXT:    csel x30, xzr, x4, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    orr x30, x25, x30
+; GISEL-NEXT:    orr x30, x6, x30
 ; GISEL-NEXT:    csel x1, x30, x1, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x30, xzr, x7, eq
+; GISEL-NEXT:    csel x30, xzr, x26, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    orr x30, x2, x30
-; GISEL-NEXT:    ldr x2, [sp, #56] ; 8-byte Reload
+; GISEL-NEXT:    orr x30, x28, x30
 ; GISEL-NEXT:    csel x1, x30, x1, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x30, xzr, x16, eq
+; GISEL-NEXT:    csel x30, xzr, x20, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    orr x30, x2, x30
+; GISEL-NEXT:    orr x30, x5, x30
 ; GISEL-NEXT:    csel x1, x30, x1, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x30, xzr, x27, eq
+; GISEL-NEXT:    csel x30, xzr, x7, eq
 ; GISEL-NEXT:    cmp x9, #4
-; GISEL-NEXT:    mov x27, x13
-; GISEL-NEXT:    orr x30, x0, x30
-; GISEL-NEXT:    ldr x0, [sp, #248] ; 8-byte Reload
+; GISEL-NEXT:    orr x30, x16, x30
+; GISEL-NEXT:    ldp x5, x16, [sp, #256] ; 16-byte Folded Reload
 ; GISEL-NEXT:    csel x1, x30, x1, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x30, xzr, x15, eq
-; GISEL-NEXT:    ldr x15, [sp, #312] ; 8-byte Reload
+; GISEL-NEXT:    csel x30, xzr, x16, eq
 ; GISEL-NEXT:    cmp x9, #5
 ; GISEL-NEXT:    orr x30, x15, x30
+; GISEL-NEXT:    ldr x15, [sp, #240] ; 8-byte Reload
 ; GISEL-NEXT:    csel x1, x30, x1, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x30, xzr, x3, eq
+; GISEL-NEXT:    csel x30, xzr, x5, eq
 ; GISEL-NEXT:    cmp x9, #6
-; GISEL-NEXT:    ldr x3, [sp, #40] ; 8-byte Reload
-; GISEL-NEXT:    orr x30, x13, x30
+; GISEL-NEXT:    orr x30, x15, x30
 ; GISEL-NEXT:    csel x1, x30, x1, eq
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x30, xzr, x14, eq
-; GISEL-NEXT:    ldp x13, x14, [sp, #256] ; 16-byte Folded Reload
+; GISEL-NEXT:    ldp x6, x14, [sp, #224] ; 16-byte Folded Reload
 ; GISEL-NEXT:    cmp x9, #7
-; GISEL-NEXT:    orr x30, x13, x30
+; GISEL-NEXT:    orr x30, x14, x30
 ; GISEL-NEXT:    csel x1, x30, x1, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x30, xzr, x14, eq
+; GISEL-NEXT:    csel x30, xzr, x13, eq
+; GISEL-NEXT:    ldr x13, [sp, #32] ; 8-byte Reload
 ; GISEL-NEXT:    cmp x9, #8
-; GISEL-NEXT:    orr x30, x3, x30
+; GISEL-NEXT:    orr x30, x13, x30
 ; GISEL-NEXT:    csel x1, x30, x1, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x30, xzr, x0, eq
+; GISEL-NEXT:    csel x30, xzr, x6, eq
 ; GISEL-NEXT:    cmp x9, #9
 ; GISEL-NEXT:    orr x30, x12, x30
 ; GISEL-NEXT:    csel x1, x30, x1, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x30, xzr, x19, eq
+; GISEL-NEXT:    csel x30, xzr, x25, eq
 ; GISEL-NEXT:    cmp x9, #10
-; GISEL-NEXT:    orr x30, x23, x30
+; GISEL-NEXT:    orr x30, x3, x30
 ; GISEL-NEXT:    csel x1, x30, x1, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x30, xzr, x17, eq
+; GISEL-NEXT:    csel x30, xzr, x24, eq
 ; GISEL-NEXT:    cmp x9, #11
-; GISEL-NEXT:    orr x30, x21, x30
+; GISEL-NEXT:    orr x30, x22, x30
 ; GISEL-NEXT:    csel x1, x30, x1, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x30, xzr, x20, eq
+; GISEL-NEXT:    csel x30, xzr, x23, eq
 ; GISEL-NEXT:    cmp x9, #12
-; GISEL-NEXT:    mov x20, x26
-; GISEL-NEXT:    orr x30, x26, x30
-; GISEL-NEXT:    mov x26, x5
+; GISEL-NEXT:    orr x30, x19, x30
 ; GISEL-NEXT:    csel x1, x30, x1, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x30, xzr, x22, eq
+; GISEL-NEXT:    csel x30, xzr, x21, eq
 ; GISEL-NEXT:    cmp x9, #13
-; GISEL-NEXT:    orr x30, x5, x30
-; GISEL-NEXT:    ldr x5, [sp, #16] ; 8-byte Reload
+; GISEL-NEXT:    orr x30, x2, x30
+; GISEL-NEXT:    ldr x2, [sp, #8] ; 8-byte Reload
 ; GISEL-NEXT:    csel x1, x30, x1, eq
 ; GISEL-NEXT:    cmp x9, #14
-; GISEL-NEXT:    csel x1, x6, x1, eq
+; GISEL-NEXT:    csel x1, x0, x1, eq
 ; GISEL-NEXT:    cmp x9, #15
-; GISEL-NEXT:    lsr x30, x10, x5
+; GISEL-NEXT:    lsr x30, x10, x2
 ; GISEL-NEXT:    csel x1, xzr, x1, eq
 ; GISEL-NEXT:    cmp x8, #0
-; GISEL-NEXT:    csel x5, x10, x1, eq
-; GISEL-NEXT:    and x10, x8, #0x3f
+; GISEL-NEXT:    csel x2, x10, x1, eq
+; GISEL-NEXT:    lsl x10, x17, x11
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    lsl x10, x4, x10
 ; GISEL-NEXT:    csel x1, xzr, x30, eq
 ; GISEL-NEXT:    cmp x9, #0
-; GISEL-NEXT:    ldp x29, x30, [sp, #416] ; 16-byte Folded Reload
+; GISEL-NEXT:    ldr x11, [sp, #24] ; 8-byte Reload
 ; GISEL-NEXT:    orr x10, x10, x1
-; GISEL-NEXT:    ldr x1, [sp, #296] ; 8-byte Reload
+; GISEL-NEXT:    ldr x1, [sp, #320] ; 8-byte Reload
 ; GISEL-NEXT:    csel x10, x10, xzr, eq
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
 ; GISEL-NEXT:    cmp x9, #1
-; GISEL-NEXT:    orr x11, x24, x11
+; GISEL-NEXT:    orr x11, x27, x11
+; GISEL-NEXT:    ldp x29, x30, [sp, #432] ; 16-byte Folded Reload
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x28, eq
+; GISEL-NEXT:    csel x11, xzr, x4, eq
 ; GISEL-NEXT:    cmp x9, #2
-; GISEL-NEXT:    orr x11, x25, x11
+; GISEL-NEXT:    orr x11, x1, x11
+; GISEL-NEXT:    ldr x1, [sp, #296] ; 8-byte Reload
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x7, eq
+; GISEL-NEXT:    csel x11, xzr, x26, eq
 ; GISEL-NEXT:    cmp x9, #3
-; GISEL-NEXT:    orr x11, x1, x11
+; GISEL-NEXT:    orr x11, x28, x11
+; GISEL-NEXT:    ldp x28, x27, [sp, #352] ; 16-byte Folded Reload
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x16, eq
+; GISEL-NEXT:    csel x11, xzr, x20, eq
 ; GISEL-NEXT:    cmp x9, #4
-; GISEL-NEXT:    ldr x16, [sp, #280] ; 8-byte Reload
-; GISEL-NEXT:    orr x11, x2, x11
+; GISEL-NEXT:    orr x11, x1, x11
+; GISEL-NEXT:    ldr x1, [sp, #280] ; 8-byte Reload
 ; GISEL-NEXT:    csel x10, x11, x10, eq
-; GISEL-NEXT:    ldr x11, [sp, #240] ; 8-byte Reload
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x11, eq
+; GISEL-NEXT:    csel x11, xzr, x7, eq
 ; GISEL-NEXT:    cmp x9, #5
-; GISEL-NEXT:    orr x11, x16, x11
+; GISEL-NEXT:    orr x11, x1, x11
 ; GISEL-NEXT:    csel x10, x11, x10, eq
-; GISEL-NEXT:    ldr x11, [sp, #32] ; 8-byte Reload
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x11, eq
+; GISEL-NEXT:    csel x11, xzr, x16, eq
+; GISEL-NEXT:    ldr x16, [sp, #272] ; 8-byte Reload
 ; GISEL-NEXT:    cmp x9, #6
-; GISEL-NEXT:    orr x11, x15, x11
+; GISEL-NEXT:    orr x11, x16, x11
 ; GISEL-NEXT:    csel x10, x11, x10, eq
-; GISEL-NEXT:    ldr x11, [sp, #328] ; 8-byte Reload
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x11, eq
+; GISEL-NEXT:    csel x11, xzr, x5, eq
 ; GISEL-NEXT:    cmp x9, #7
-; GISEL-NEXT:    orr x11, x27, x11
-; GISEL-NEXT:    ldp x28, x27, [sp, #336] ; 16-byte Folded Reload
+; GISEL-NEXT:    orr x11, x15, x11
 ; GISEL-NEXT:    csel x10, x11, x10, eq
-; GISEL-NEXT:    ldr x11, [sp, #320] ; 8-byte Reload
+; GISEL-NEXT:    ldr x11, [sp, #336] ; 8-byte Reload
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    csel x11, xzr, x11, eq
 ; GISEL-NEXT:    cmp x9, #8
-; GISEL-NEXT:    orr x11, x13, x11
-; GISEL-NEXT:    ldr x13, [sp, #144] ; 8-byte Reload
+; GISEL-NEXT:    orr x11, x14, x11
 ; GISEL-NEXT:    csel x10, x11, x10, eq
+; GISEL-NEXT:    ldr x11, [sp, #328] ; 8-byte Reload
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x14, eq
+; GISEL-NEXT:    csel x11, xzr, x11, eq
 ; GISEL-NEXT:    cmp x9, #9
-; GISEL-NEXT:    orr x11, x3, x11
+; GISEL-NEXT:    orr x11, x13, x11
+; GISEL-NEXT:    ldr x13, [sp, #136] ; 8-byte Reload
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    tst x8, #0x3f
-; GISEL-NEXT:    csel x11, xzr, x0, eq
+; GISEL-NEXT:    csel x11, xzr, x6, eq
 ; GISEL-NEXT:    cmp x9, #10
 ; GISEL-NEXT:    orr x11, x12, x11
 ; GISEL-NEXT:    csel x10, x11, x10, eq
-; GISEL-NEXT:    ldr x11, [sp, #232] ; 8-byte Reload
+; GISEL-NEXT:    ldr x11, [sp, #216] ; 8-byte Reload
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    str x11, [x13]
-; GISEL-NEXT:    ldp x12, x11, [sp, #216] ; 16-byte Folded Reload
+; GISEL-NEXT:    ldp x12, x11, [sp, #200] ; 16-byte Folded Reload
 ; GISEL-NEXT:    stp x11, x12, [x13, #8]
-; GISEL-NEXT:    csel x11, xzr, x19, eq
+; GISEL-NEXT:    csel x11, xzr, x25, eq
 ; GISEL-NEXT:    cmp x9, #11
-; GISEL-NEXT:    orr x11, x23, x11
-; GISEL-NEXT:    ldp x24, x23, [sp, #368] ; 16-byte Folded Reload
+; GISEL-NEXT:    orr x11, x3, x11
+; GISEL-NEXT:    ldp x26, x25, [sp, #368] ; 16-byte Folded Reload
 ; GISEL-NEXT:    csel x10, x11, x10, eq
-; GISEL-NEXT:    ldr x11, [sp, #208] ; 8-byte Reload
+; GISEL-NEXT:    ldr x11, [sp, #192] ; 8-byte Reload
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    str x11, [x13, #24]
-; GISEL-NEXT:    ldp x12, x11, [sp, #192] ; 16-byte Folded Reload
+; GISEL-NEXT:    ldp x12, x11, [sp, #176] ; 16-byte Folded Reload
 ; GISEL-NEXT:    stp x11, x12, [x13, #32]
-; GISEL-NEXT:    csel x11, xzr, x17, eq
+; GISEL-NEXT:    csel x11, xzr, x24, eq
 ; GISEL-NEXT:    cmp x9, #12
-; GISEL-NEXT:    orr x11, x21, x11
+; GISEL-NEXT:    orr x11, x22, x11
 ; GISEL-NEXT:    csel x10, x11, x10, eq
-; GISEL-NEXT:    ldr x11, [sp, #184] ; 8-byte Reload
+; GISEL-NEXT:    ldr x11, [sp, #168] ; 8-byte Reload
 ; GISEL-NEXT:    tst x8, #0x3f
 ; GISEL-NEXT:    str x11, [x13, #48]
-; GISEL-NEXT:    ldp x12, x11, [sp, #168] ; 16-byte Folded Reload
+; GISEL-NEXT:    ldp x12, x11, [sp, #152] ; 16-byte Folded Reload
 ; GISEL-NEXT:    stp x11, x12, [x13, #56]
-; GISEL-NEXT:    ldr x11, [sp, #112] ; 8-byte Reload
-; GISEL-NEXT:    ldr x12, [sp, #136] ; 8-byte Reload
-; GISEL-NEXT:    csel x11, xzr, x11, eq
+; GISEL-NEXT:    csel x11, xzr, x23, eq
 ; GISEL-NEXT:    cmp x9, #13
-; GISEL-NEXT:    orr x11, x20, x11
-; GISEL-NEXT:    ldp x20, x19, [sp, #400] ; 16-byte Folded Reload
+; GISEL-NEXT:    orr x11, x19, x11
+; GISEL-NEXT:    ldr x12, [sp, #312] ; 8-byte Reload
 ; GISEL-NEXT:    csel x10, x11, x10, eq
-; GISEL-NEXT:    ldr x11, [sp, #160] ; 8-byte Reload
+; GISEL-NEXT:    ldr x11, [sp, #144] ; 8-byte Reload
 ; GISEL-NEXT:    tst x8, #0x3f
+; GISEL-NEXT:    ldp x20, x19, [sp, #416] ; 16-byte Folded Reload
 ; GISEL-NEXT:    str x11, [x13, #72]
-; GISEL-NEXT:    ldr x11, [sp, #152] ; 8-byte Reload
+; GISEL-NEXT:    ldr x11, [sp, #128] ; 8-byte Reload
+; GISEL-NEXT:    ldp x24, x23, [sp, #384] ; 16-byte Folded Reload
 ; GISEL-NEXT:    str x11, [x13, #80]
-; GISEL-NEXT:    csel x11, xzr, x22, eq
+; GISEL-NEXT:    csel x11, xzr, x21, eq
 ; GISEL-NEXT:    cmp x9, #14
-; GISEL-NEXT:    orr x11, x26, x11
-; GISEL-NEXT:    ldp x22, x21, [sp, #384] ; 16-byte Folded Reload
+; GISEL-NEXT:    orr x11, x12, x11
+; GISEL-NEXT:    ldr x12, [sp, #120] ; 8-byte Reload
 ; GISEL-NEXT:    csel x10, x11, x10, eq
 ; GISEL-NEXT:    cmp x9, #15
-; GISEL-NEXT:    ldr x9, [sp, #128] ; 8-byte Reload
-; GISEL-NEXT:    ldp x26, x25, [sp, #352] ; 16-byte Folded Reload
+; GISEL-NEXT:    ldr x9, [sp, #112] ; 8-byte Reload
+; GISEL-NEXT:    ldp x22, x21, [sp, #400] ; 16-byte Folded Reload
 ; GISEL-NEXT:    stp x12, x9, [x13, #88]
-; GISEL-NEXT:    csel x9, x6, x10, eq
+; GISEL-NEXT:    csel x9, x0, x10, eq
 ; GISEL-NEXT:    cmp x8, #0
-; GISEL-NEXT:    ldr x8, [sp, #120] ; 8-byte Reload
-; GISEL-NEXT:    stp x8, x5, [x13, #104]
-; GISEL-NEXT:    csel x8, x4, x9, eq
+; GISEL-NEXT:    ldr x8, [sp, #104] ; 8-byte Reload
+; GISEL-NEXT:    stp x8, x2, [x13, #104]
+; GISEL-NEXT:    csel x8, x17, x9, eq
 ; GISEL-NEXT:    str x8, [x13, #120]
-; GISEL-NEXT:    add sp, sp, #432
+; GISEL-NEXT:    add sp, sp, #448
 ; GISEL-NEXT:    ret
 entry:
   %input_val = load i1024, ptr %input, align 128
diff --git a/llvm/test/CodeGen/AArch64/frem-power2.ll b/llvm/test/CodeGen/AArch64/frem-power2.ll
index 548079dc5c4aa..7314ee72e8d20 100644
--- a/llvm/test/CodeGen/AArch64/frem-power2.ll
+++ b/llvm/test/CodeGen/AArch64/frem-power2.ll
@@ -665,9 +665,8 @@ define float @frem2_const_sitofp(float %x, i32 %sa) {
 ; CHECK-GI-LABEL: frem2_const_sitofp:
 ; CHECK-GI:       // %bb.0: // %entry
 ; CHECK-GI-NEXT:    mov w8, #1 // =0x1
-; CHECK-GI-NEXT:    and w9, w0, #0x1f
 ; CHECK-GI-NEXT:    fmov s0, #12.50000000
-; CHECK-GI-NEXT:    lsl w8, w8, w9
+; CHECK-GI-NEXT:    lsl w8, w8, w0
 ; CHECK-GI-NEXT:    scvtf s1, w8
 ; CHECK-GI-NEXT:    b fmodf
 entry:
@@ -695,9 +694,8 @@ define float @frem2_constneg_sitofp(float %x, i32 %sa) {
 ; CHECK-GI-LABEL: frem2_constneg_sitofp:
 ; CHECK-GI:       // %bb.0: // %entry
 ; CHECK-GI-NEXT:    mov w8, #1 // =0x1
-; CHECK-GI-NEXT:    and w9, w0, #0x1f
 ; CHECK-GI-NEXT:    fmov s0, #-12.50000000
-; CHECK-GI-NEXT:    lsl w8, w8, w9
+; CHECK-GI-NEXT:    lsl w8, w8, w0
 ; CHECK-GI-NEXT:    scvtf s1, w8
 ; CHECK-GI-NEXT:    b fmodf
 entry:
diff --git a/llvm/test/CodeGen/AArch64/fsh.ll b/llvm/test/CodeGen/AArch64/fsh.ll
index 6a36a0f3fe5fd..a05df3a86cec9 100644
--- a/llvm/test/CodeGen/AArch64/fsh.ll
+++ b/llvm/test/CodeGen/AArch64/fsh.ll
@@ -189,33 +189,33 @@ define i128 @rotl_i128(i128 %a, i128 %c) {
 ; CHECK-GI-NEXT:    and x9, x2, #0x7f
 ; CHECK-GI-NEXT:    neg x10, x2
 ; CHECK-GI-NEXT:    sub x12, x8, x9
-; CHECK-GI-NEXT:    sub x11, x9, #64
-; CHECK-GI-NEXT:    lsl x14, x1, x9
+; CHECK-GI-NEXT:    lsl x13, x1, x2
+; CHECK-GI-NEXT:    sub x14, x9, #64
 ; CHECK-GI-NEXT:    lsr x12, x0, x12
-; CHECK-GI-NEXT:    lsl x13, x0, x9
 ; CHECK-GI-NEXT:    cmp x9, #64
 ; CHECK-GI-NEXT:    and x9, x10, #0x7f
-; CHECK-GI-NEXT:    lsl x11, x0, x11
-; CHECK-GI-NEXT:    orr x12, x12, x14
+; CHECK-GI-NEXT:    lsl x14, x0, x14
+; CHECK-GI-NEXT:    lsl x11, x0, x2
 ; CHECK-GI-NEXT:    sub x8, x8, x9
-; CHECK-GI-NEXT:    sub x14, x9, #64
-; CHECK-GI-NEXT:    csel x11, x12, x11, lo
-; CHECK-GI-NEXT:    lsr x12, x0, x9
+; CHECK-GI-NEXT:    orr x12, x12, x13
+; CHECK-GI-NEXT:    sub x13, x9, #64
 ; CHECK-GI-NEXT:    lsl x8, x1, x8
-; CHECK-GI-NEXT:    csel x13, x13, xzr, lo
+; CHECK-GI-NEXT:    csel x12, x12, x14, lo
+; CHECK-GI-NEXT:    lsr x14, x0, x9
+; CHECK-GI-NEXT:    csel x11, x11, xzr, lo
 ; CHECK-GI-NEXT:    tst x2, #0x7f
-; CHECK-GI-NEXT:    lsr x14, x1, x14
-; CHECK-GI-NEXT:    csel x11, x1, x11, eq
-; CHECK-GI-NEXT:    orr x8, x12, x8
+; CHECK-GI-NEXT:    lsr x13, x1, x13
+; CHECK-GI-NEXT:    csel x12, x1, x12, eq
+; CHECK-GI-NEXT:    orr x8, x14, x8
 ; CHECK-GI-NEXT:    cmp x9, #64
-; CHECK-GI-NEXT:    lsr x12, x1, x9
-; CHECK-GI-NEXT:    csel x8, x8, x14, lo
+; CHECK-GI-NEXT:    lsr x14, x1, x9
+; CHECK-GI-NEXT:    csel x8, x8, x13, lo
 ; CHECK-GI-NEXT:    tst x10, #0x7f
 ; CHECK-GI-NEXT:    csel x8, x0, x8, eq
 ; CHECK-GI-NEXT:    cmp x9, #64
-; CHECK-GI-NEXT:    csel x9, x12, xzr, lo
-; CHECK-GI-NEXT:    orr x0, x13, x8
-; CHECK-GI-NEXT:    orr x1, x11, x9
+; CHECK-GI-NEXT:    csel x9, x14, xzr, lo
+; CHECK-GI-NEXT:    orr x0, x11, x8
+; CHECK-GI-NEXT:    orr x1, x12, x9
 ; CHECK-GI-NEXT:    ret
 entry:
   %d = call i128 @llvm.fshl(i128 %a, i128 %a, i128 %c)
@@ -252,22 +252,22 @@ define i128 @rotr_i128(i128 %a, i128 %c) {
 ; CHECK-GI-NEXT:    and x14, x13, #0x7f
 ; CHECK-GI-NEXT:    cmp x9, #64
 ; CHECK-GI-NEXT:    sub x8, x8, x14
-; CHECK-GI-NEXT:    lsl x15, x1, x14
+; CHECK-GI-NEXT:    sub x15, x14, #64
 ; CHECK-GI-NEXT:    orr x10, x12, x10
 ; CHECK-GI-NEXT:    lsr x12, x1, x9
 ; CHECK-GI-NEXT:    lsr x8, x0, x8
 ; CHECK-GI-NEXT:    csel x10, x10, x11, lo
-; CHECK-GI-NEXT:    sub x11, x14, #64
+; CHECK-GI-NEXT:    lsl x11, x1, x13
 ; CHECK-GI-NEXT:    tst x2, #0x7f
 ; CHECK-GI-NEXT:    csel x10, x0, x10, eq
 ; CHECK-GI-NEXT:    cmp x9, #64
-; CHECK-GI-NEXT:    lsl x9, x0, x14
-; CHECK-GI-NEXT:    lsl x11, x0, x11
+; CHECK-GI-NEXT:    lsl x9, x0, x13
+; CHECK-GI-NEXT:    lsl x15, x0, x15
 ; CHECK-GI-NEXT:    csel x12, x12, xzr, lo
-; CHECK-GI-NEXT:    orr x8, x8, x15
+; CHECK-GI-NEXT:    orr x8, x8, x11
 ; CHECK-GI-NEXT:    cmp x14, #64
 ; CHECK-GI-NEXT:    csel x9, x9, xzr, lo
-; CHECK-GI-NEXT:    csel x8, x8, x11, lo
+; CHECK-GI-NEXT:    csel x8, x8, x15, lo
 ; CHECK-GI-NEXT:    tst x13, #0x7f
 ; CHECK-GI-NEXT:    csel x8, x1, x8, eq
 ; CHECK-GI-NEXT:    orr x0, x10, x9
@@ -404,9 +404,8 @@ define i32 @fshl_i32(i32 %a, i32 %b, i32 %c) {
 ; CHECK-GI:       // %bb.0: // %entry
 ; CHECK-GI-NEXT:    mov w8, #31 // =0x1f
 ; CHECK-GI-NEXT:    lsr w9, w1, #1
-; CHECK-GI-NEXT:    and w10, w2, #0x1f
+; CHECK-GI-NEXT:    lsl w10, w0, w2
 ; CHECK-GI-NEXT:    bic w8, w8, w2
-; CHECK-GI-NEXT:    lsl w10, w0, w10
 ; CHECK-GI-NEXT:    lsr w8, w9, w8
 ; CHECK-GI-NEXT:    orr w0, w10, w8
 ; CHECK-GI-NEXT:    ret
@@ -427,12 +426,11 @@ define i32 @fshr_i32(i32 %a, i32 %b, i32 %c) {
 ;
 ; CHECK-GI-LABEL: fshr_i32:
 ; CHECK-GI:       // %bb.0: // %entry
-; CHECK-GI-NEXT:    mov w8, #31 // =0x1f
-; CHECK-GI-NEXT:    lsl w9, w0, #1
-; CHECK-GI-NEXT:    and w10, w2, #0x1f
-; CHECK-GI-NEXT:    bic w8, w8, w2
-; CHECK-GI-NEXT:    lsl w8, w9, w8
-; CHECK-GI-NEXT:    lsr w9, w1, w10
+; CHECK-GI-NEXT:    lsl w8, w0, #1
+; CHECK-GI-NEXT:    and w9, w2, #0x1f
+; CHECK-GI-NEXT:    mvn w10, w2
+; CHECK-GI-NEXT:    lsr w9, w1, w9
+; CHECK-GI-NEXT:    lsl w8, w8, w10
 ; CHECK-GI-NEXT:    orr w0, w8, w9
 ; CHECK-GI-NEXT:    ret
 entry:
@@ -454,9 +452,8 @@ define i64 @fshl_i64(i64 %a, i64 %b, i64 %c) {
 ; CHECK-GI:       // %bb.0: // %entry
 ; CHECK-GI-NEXT:    mov w8, #63 // =0x3f
 ; CHECK-GI-NEXT:    lsr x9, x1, #1
-; CHECK-GI-NEXT:    and x10, x2, #0x3f
+; CHECK-GI-NEXT:    lsl x10, x0, x2
 ; CHECK-GI-NEXT:    bic x8, x8, x2
-; CHECK-GI-NEXT:    lsl x10, x0, x10
 ; CHECK-GI-NEXT:    lsr x8, x9, x8
 ; CHECK-GI-NEXT:    orr x0, x10, x8
 ; CHECK-GI-NEXT:    ret
@@ -477,12 +474,11 @@ define i64 @fshr_i64(i64 %a, i64 %b, i64 %c) {
 ;
 ; CHECK-GI-LABEL: fshr_i64:
 ; CHECK-GI:       // %bb.0: // %entry
-; CHECK-GI-NEXT:    mov w8, #63 // =0x3f
-; CHECK-GI-NEXT:    lsl x9, x0, #1
-; CHECK-GI-NEXT:    and x10, x2, #0x3f
-; CHECK-GI-NEXT:    bic x8, x8, x2
-; CHECK-GI-NEXT:    lsl x8, x9, x8
-; CHECK-GI-NEXT:    lsr x9, x1, x10
+; CHECK-GI-NEXT:    lsl x8, x0, #1
+; CHECK-GI-NEXT:    and x9, x2, #0x3f
+; CHECK-GI-NEXT:    mvn x10, x2
+; CHECK-GI-NEXT:    lsr x9, x1, x9
+; CHECK-GI-NEXT:    lsl x8, x8, x10
 ; CHECK-GI-NEXT:    orr x0, x8, x9
 ; CHECK-GI-NEXT:    ret
 entry:
@@ -512,22 +508,22 @@ define i128 @fshl_i128(i128 %a, i128 %b, i128 %c) {
 ; CHECK-GI:       // %bb.0: // %entry
 ; CHECK-GI-NEXT:    mov w8, #64 // =0x40
 ; CHECK-GI-NEXT:    and x9, x4, #0x7f
-; CHECK-GI-NEXT:    mov w10, #127 // =0x7f
+; CHECK-GI-NEXT:    lsl x13, x1, x4
 ; CHECK-GI-NEXT:    sub x12, x8, x9
-; CHECK-GI-NEXT:    lsl x13, x1, x9
-; CHECK-GI-NEXT:    bic x10, x10, x4
+; CHECK-GI-NEXT:    mov w10, #127 // =0x7f
+; CHECK-GI-NEXT:    sub x15, x9, #64
 ; CHECK-GI-NEXT:    lsr x12, x0, x12
-; CHECK-GI-NEXT:    sub x14, x9, #64
-; CHECK-GI-NEXT:    lsl x15, x0, x9
+; CHECK-GI-NEXT:    bic x10, x10, x4
 ; CHECK-GI-NEXT:    extr x16, x3, x2, #1
 ; CHECK-GI-NEXT:    cmp x9, #64
+; CHECK-GI-NEXT:    lsl x14, x0, x4
 ; CHECK-GI-NEXT:    sub x8, x8, x10
 ; CHECK-GI-NEXT:    orr x9, x12, x13
 ; CHECK-GI-NEXT:    lsr x12, x3, #1
-; CHECK-GI-NEXT:    lsl x13, x0, x14
-; CHECK-GI-NEXT:    csel x14, x15, xzr, lo
+; CHECK-GI-NEXT:    lsl x13, x0, x15
 ; CHECK-GI-NEXT:    sub x15, x10, #64
 ; CHECK-GI-NEXT:    lsr x17, x16, x10
+; CHECK-GI-NEXT:    csel x14, x14, xzr, lo
 ; CHECK-GI-NEXT:    lsl x8, x12, x8
 ; CHECK-GI-NEXT:    csel x9, x9, x13, lo
 ; CHECK-GI-NEXT:    tst x4, #0x7f
@@ -575,32 +571,32 @@ define i128 @fshr_i128(i128 %a, i128 %b, i128 %c) {
 ; CHECK-GI-NEXT:    extr x10, x1, x0, #63
 ; CHECK-GI-NEXT:    bic x8, x8, x4
 ; CHECK-GI-NEXT:    mov w11, #64 // =0x40
-; CHECK-GI-NEXT:    and x14, x4, #0x7f
-; CHECK-GI-NEXT:    sub x12, x11, x8
-; CHECK-GI-NEXT:    lsl x13, x10, x8
-; CHECK-GI-NEXT:    lsl x16, x9, x8
-; CHECK-GI-NEXT:    lsr x12, x9, x12
+; CHECK-GI-NEXT:    mvn x12, x4
+; CHECK-GI-NEXT:    sub x13, x11, x8
+; CHECK-GI-NEXT:    lsl x14, x10, x12
+; CHECK-GI-NEXT:    and x15, x4, #0x7f
+; CHECK-GI-NEXT:    lsr x13, x9, x13
+; CHECK-GI-NEXT:    lsl x16, x9, x12
 ; CHECK-GI-NEXT:    sub x17, x8, #64
 ; CHECK-GI-NEXT:    cmp x8, #64
 ; CHECK-GI-NEXT:    lsl x8, x9, x17
-; CHECK-GI-NEXT:    sub x11, x11, x14
-; CHECK-GI-NEXT:    mvn x15, x4
-; CHECK-GI-NEXT:    orr x12, x12, x13
+; CHECK-GI-NEXT:    sub x11, x11, x15
+; CHECK-GI-NEXT:    orr x13, x13, x14
 ; CHECK-GI-NEXT:    csel x9, x16, xzr, lo
-; CHECK-GI-NEXT:    sub x13, x14, #64
-; CHECK-GI-NEXT:    lsr x16, x2, x14
+; CHECK-GI-NEXT:    sub x14, x15, #64
+; CHECK-GI-NEXT:    lsr x16, x2, x15
 ; CHECK-GI-NEXT:    lsl x11, x3, x11
-; CHECK-GI-NEXT:    csel x8, x12, x8, lo
-; CHECK-GI-NEXT:    tst x15, #0x7f
-; CHECK-GI-NEXT:    lsr x12, x3, x13
+; CHECK-GI-NEXT:    csel x8, x13, x8, lo
+; CHECK-GI-NEXT:    tst x12, #0x7f
+; CHECK-GI-NEXT:    lsr x12, x3, x14
 ; CHECK-GI-NEXT:    csel x8, x10, x8, eq
 ; CHECK-GI-NEXT:    orr x10, x16, x11
-; CHECK-GI-NEXT:    cmp x14, #64
-; CHECK-GI-NEXT:    lsr x11, x3, x14
+; CHECK-GI-NEXT:    cmp x15, #64
+; CHECK-GI-NEXT:    lsr x11, x3, x15
 ; CHECK-GI-NEXT:    csel x10, x10, x12, lo
 ; CHECK-GI-NEXT:    tst x4, #0x7f
 ; CHECK-GI-NEXT:    csel x10, x2, x10, eq
-; CHECK-GI-NEXT:    cmp x14, #64
+; CHECK-GI-NEXT:    cmp x15, #64
 ; CHECK-GI-NEXT:    csel x11, x11, xzr, lo
 ; CHECK-GI-NEXT:    orr x0, x9, x10
 ; CHECK-GI-NEXT:    orr x1, x8, x11
@@ -1768,53 +1764,52 @@ define <2 x i128> @rotl_v2i128(<2 x i128> %a, <2 x i128> %c) {
 ; CHECK-GI:       // %bb.0: // %entry
 ; CHECK-GI-NEXT:    and x8, x4, #0x7f
 ; CHECK-GI-NEXT:    mov w9, #64 // =0x40
-; CHECK-GI-NEXT:    neg x13, x4
+; CHECK-GI-NEXT:    lsl x11, x1, x4
 ; CHECK-GI-NEXT:    sub x10, x9, x8
-; CHECK-GI-NEXT:    lsl x12, x1, x8
-; CHECK-GI-NEXT:    sub x11, x8, #64
+; CHECK-GI-NEXT:    sub x12, x8, #64
+; CHECK-GI-NEXT:    lsl x14, x0, x4
 ; CHECK-GI-NEXT:    lsr x10, x0, x10
-; CHECK-GI-NEXT:    lsl x14, x0, x8
-; CHECK-GI-NEXT:    lsl x11, x0, x11
+; CHECK-GI-NEXT:    lsl x12, x0, x12
 ; CHECK-GI-NEXT:    cmp x8, #64
-; CHECK-GI-NEXT:    neg x15, x6
-; CHECK-GI-NEXT:    orr x8, x10, x12
+; CHECK-GI-NEXT:    lsl x16, x2, x6
+; CHECK-GI-NEXT:    lsl x17, x3, x6
+; CHECK-GI-NEXT:    neg x13, x4
+; CHECK-GI-NEXT:    orr x8, x10, x11
 ; CHECK-GI-NEXT:    and x10, x6, #0x7f
-; CHECK-GI-NEXT:    csel x12, x14, xzr, lo
+; CHECK-GI-NEXT:    csel x11, x14, xzr, lo
 ; CHECK-GI-NEXT:    sub x14, x9, x10
-; CHECK-GI-NEXT:    csel x8, x8, x11, lo
+; CHECK-GI-NEXT:    csel x8, x8, x12, lo
 ; CHECK-GI-NEXT:    tst x4, #0x7f
-; CHECK-GI-NEXT:    sub x11, x10, #64
-; CHECK-GI-NEXT:    lsl x16, x2, x10
+; CHECK-GI-NEXT:    sub x12, x10, #64
 ; CHECK-GI-NEXT:    lsr x14, x2, x14
-; CHECK-GI-NEXT:    lsl x17, x3, x10
 ; CHECK-GI-NEXT:    csel x8, x1, x8, eq
-; CHECK-GI-NEXT:    lsl x11, x2, x11
+; CHECK-GI-NEXT:    lsl x12, x2, x12
 ; CHECK-GI-NEXT:    cmp x10, #64
-; CHECK-GI-NEXT:    and x4, x15, #0x7f
+; CHECK-GI-NEXT:    neg x15, x6
 ; CHECK-GI-NEXT:    orr x10, x14, x17
 ; CHECK-GI-NEXT:    csel x14, x16, xzr, lo
 ; CHECK-GI-NEXT:    and x16, x13, #0x7f
-; CHECK-GI-NEXT:    csel x10, x10, x11, lo
-; CHECK-GI-NEXT:    sub x11, x9, x16
+; CHECK-GI-NEXT:    csel x10, x10, x12, lo
+; CHECK-GI-NEXT:    sub x12, x9, x16
 ; CHECK-GI-NEXT:    sub x17, x16, #64
 ; CHECK-GI-NEXT:    lsr x18, x0, x16
-; CHECK-GI-NEXT:    lsl x11, x1, x11
+; CHECK-GI-NEXT:    lsl x12, x1, x12
 ; CHECK-GI-NEXT:    tst x6, #0x7f
+; CHECK-GI-NEXT:    and x4, x15, #0x7f
 ; CHECK-GI-NEXT:    lsr x17, x1, x17
 ; CHECK-GI-NEXT:    csel x10, x3, x10, eq
+; CHECK-GI-NEXT:    orr x12, x18, x12
 ; CHECK-GI-NEXT:    cmp x16, #64
-; CHECK-GI-NEXT:    orr x11, x18, x11
 ; CHECK-GI-NEXT:    sub x9, x9, x4
 ; CHECK-GI-NEXT:    lsr x1, x1, x16
-; CHECK-GI-NEXT:    csel x11, x11, x17, lo
+; CHECK-GI-NEXT:    csel x12, x12, x17, lo
 ; CHECK-GI-NEXT:    tst x13, #0x7f
 ; CHECK-GI-NEXT:    sub x13, x4, #64
 ; CHECK-GI-NEXT:    lsr x17, x2, x4
 ; CHECK-GI-NEXT:    lsl x9, x3, x9
-; CHECK-GI-NEXT:    csel x11, x0, x11, eq
+; CHECK-GI-NEXT:    csel x12, x0, x12, eq
 ; CHECK-GI-NEXT:    cmp x16, #64
 ; CHECK-GI-NEXT:    lsr x13, x3, x13
-; CHECK-GI-NEXT:    orr x0, x12, x11
 ; CHECK-GI-NEXT:    csel x16, x1, xzr, lo
 ; CHECK-GI-NEXT:    orr x9, x17, x9
 ; CHECK-GI-NEXT:    cmp x4, #64
@@ -1823,8 +1818,9 @@ define <2 x i128> @rotl_v2i128(<2 x i128> %a, <2 x i128> %c) {
 ; CHECK-GI-NEXT:    tst x15, #0x7f
 ; CHECK-GI-NEXT:    csel x9, x2, x9, eq
 ; CHECK-GI-NEXT:    cmp x4, #64
-; CHECK-GI-NEXT:    orr x1, x8, x16
+; CHECK-GI-NEXT:    orr x0, x11, x12
 ; CHECK-GI-NEXT:    csel x13, x17, xzr, lo
+; CHECK-GI-NEXT:    orr x1, x8, x16
 ; CHECK-GI-NEXT:    orr x2, x14, x9
 ; CHECK-GI-NEXT:    orr x3, x10, x13
 ; CHECK-GI-NEXT:    ret
@@ -1890,6 +1886,7 @@ define <2 x i128> @rotr_v2i128(<2 x i128> %a, <2 x i128> %c) {
 ; CHECK-GI-NEXT:    cmp x14, #64
 ; CHECK-GI-NEXT:    orr x8, x8, x15
 ; CHECK-GI-NEXT:    neg x16, x6
+; CHECK-GI-NEXT:    lsl x18, x1, x13
 ; CHECK-GI-NEXT:    csel x8, x8, x11, lo
 ; CHECK-GI-NEXT:    tst x6, #0x7f
 ; CHECK-GI-NEXT:    and x11, x13, #0x7f
@@ -1898,8 +1895,7 @@ define <2 x i128> @rotr_v2i128(<2 x i128> %a, <2 x i128> %c) {
 ; CHECK-GI-NEXT:    sub x14, x9, x11
 ; CHECK-GI-NEXT:    sub x15, x11, #64
 ; CHECK-GI-NEXT:    lsr x14, x0, x14
-; CHECK-GI-NEXT:    lsl x18, x1, x11
-; CHECK-GI-NEXT:    lsl x4, x0, x11
+; CHECK-GI-NEXT:    lsl x4, x0, x13
 ; CHECK-GI-NEXT:    lsl x15, x0, x15
 ; CHECK-GI-NEXT:    and x0, x16, #0x7f
 ; CHECK-GI-NEXT:    csel x17, x17, xzr, lo
@@ -1909,19 +1905,19 @@ define <2 x i128> @rotr_v2i128(<2 x i128> %a, <2 x i128> %c) {
 ; CHECK-GI-NEXT:    csel x14, x14, x15, lo
 ; CHECK-GI-NEXT:    sub x15, x0, #64
 ; CHECK-GI-NEXT:    lsr x9, x2, x9
-; CHECK-GI-NEXT:    lsl x18, x3, x0
+; CHECK-GI-NEXT:    lsl x18, x3, x16
 ; CHECK-GI-NEXT:    csel x11, x4, xzr, lo
 ; CHECK-GI-NEXT:    tst x13, #0x7f
-; CHECK-GI-NEXT:    lsl x13, x2, x0
+; CHECK-GI-NEXT:    lsl x13, x2, x16
 ; CHECK-GI-NEXT:    lsl x15, x2, x15
 ; CHECK-GI-NEXT:    csel x14, x1, x14, eq
 ; CHECK-GI-NEXT:    orr x9, x9, x18
 ; CHECK-GI-NEXT:    cmp x0, #64
+; CHECK-GI-NEXT:    orr x0, x10, x11
 ; CHECK-GI-NEXT:    csel x13, x13, xzr, lo
 ; CHECK-GI-NEXT:    csel x9, x9, x15, lo
 ; CHECK-GI-NEXT:    tst x16, #0x7f
 ; CHECK-GI-NEXT:    csel x9, x3, x9, eq
-; CHECK-GI-NEXT:    orr x0, x10, x11
 ; CHECK-GI-NEXT:    orr x1, x12, x14
 ; CHECK-GI-NEXT:    orr x2, x8, x13
 ; CHECK-GI-NEXT:    orr x3, x17, x9
@@ -2876,67 +2872,67 @@ define <2 x i128> @fshl_v2i128(<2 x i128> %a, <2 x i128> %b, <2 x i128> %c) {
 ; CHECK-GI-NEXT:    ldr x12, [sp, #32]
 ; CHECK-GI-NEXT:    mov w13, #127 // =0x7f
 ; CHECK-GI-NEXT:    and x8, x11, #0x7f
+; CHECK-GI-NEXT:    lsl x17, x1, x11
 ; CHECK-GI-NEXT:    and x14, x12, #0x7f
-; CHECK-GI-NEXT:    mvn x18, x11
 ; CHECK-GI-NEXT:    sub x10, x9, x8
 ; CHECK-GI-NEXT:    sub x15, x8, #64
-; CHECK-GI-NEXT:    lsl x17, x1, x8
+; CHECK-GI-NEXT:    cmp x8, #64
 ; CHECK-GI-NEXT:    lsr x16, x0, x10
 ; CHECK-GI-NEXT:    lsl x15, x0, x15
-; CHECK-GI-NEXT:    cmp x8, #64
-; CHECK-GI-NEXT:    lsl x19, x0, x8
-; CHECK-GI-NEXT:    lsl x0, x3, x14
+; CHECK-GI-NEXT:    lsl x19, x0, x11
+; CHECK-GI-NEXT:    lsl x0, x3, x12
+; CHECK-GI-NEXT:    mvn x18, x11
 ; CHECK-GI-NEXT:    mvn x10, x12
 ; CHECK-GI-NEXT:    orr x16, x16, x17
 ; CHECK-GI-NEXT:    sub x17, x14, #64
+; CHECK-GI-NEXT:    csel x8, x19, xzr, lo
 ; CHECK-GI-NEXT:    csel x15, x16, x15, lo
 ; CHECK-GI-NEXT:    sub x16, x9, x14
-; CHECK-GI-NEXT:    csel x8, x19, xzr, lo
-; CHECK-GI-NEXT:    lsr x16, x2, x16
 ; CHECK-GI-NEXT:    tst x11, #0x7f
-; CHECK-GI-NEXT:    lsl x19, x2, x14
+; CHECK-GI-NEXT:    lsr x16, x2, x16
+; CHECK-GI-NEXT:    lsl x19, x2, x12
 ; CHECK-GI-NEXT:    lsl x17, x2, x17
 ; CHECK-GI-NEXT:    csel x15, x1, x15, eq
 ; CHECK-GI-NEXT:    cmp x14, #64
-; CHECK-GI-NEXT:    orr x16, x16, x0
 ; CHECK-GI-NEXT:    bic x11, x13, x11
+; CHECK-GI-NEXT:    orr x16, x16, x0
 ; CHECK-GI-NEXT:    csel x14, x19, xzr, lo
+; CHECK-GI-NEXT:    extr x0, x5, x4, #1
 ; CHECK-GI-NEXT:    csel x16, x16, x17, lo
 ; CHECK-GI-NEXT:    tst x12, #0x7f
 ; CHECK-GI-NEXT:    lsr x17, x5, #1
-; CHECK-GI-NEXT:    extr x0, x5, x4, #1
 ; CHECK-GI-NEXT:    bic x12, x13, x12
 ; CHECK-GI-NEXT:    csel x13, x3, x16, eq
 ; CHECK-GI-NEXT:    sub x16, x9, x11
 ; CHECK-GI-NEXT:    sub x1, x11, #64
-; CHECK-GI-NEXT:    lsr x3, x7, #1
 ; CHECK-GI-NEXT:    lsr x2, x0, x11
 ; CHECK-GI-NEXT:    lsl x16, x17, x16
+; CHECK-GI-NEXT:    lsr x3, x7, #1
 ; CHECK-GI-NEXT:    extr x4, x7, x6, #1
 ; CHECK-GI-NEXT:    lsr x1, x17, x1
+; CHECK-GI-NEXT:    orr x16, x2, x16
 ; CHECK-GI-NEXT:    cmp x11, #64
 ; CHECK-GI-NEXT:    sub x9, x9, x12
-; CHECK-GI-NEXT:    orr x16, x2, x16
 ; CHECK-GI-NEXT:    lsr x17, x17, x11
-; CHECK-GI-NEXT:    lsl x9, x3, x9
 ; CHECK-GI-NEXT:    csel x16, x16, x1, lo
 ; CHECK-GI-NEXT:    tst x18, #0x7f
 ; CHECK-GI-NEXT:    sub x18, x12, #64
 ; CHECK-GI-NEXT:    lsr x1, x4, x12
+; CHECK-GI-NEXT:    lsl x9, x3, x9
 ; CHECK-GI-NEXT:    csel x16, x0, x16, eq
 ; CHECK-GI-NEXT:    cmp x11, #64
 ; CHECK-GI-NEXT:    lsr x11, x3, x18
 ; CHECK-GI-NEXT:    csel x17, x17, xzr, lo
-; CHECK-GI-NEXT:    cmp x12, #64
 ; CHECK-GI-NEXT:    orr x9, x1, x9
+; CHECK-GI-NEXT:    cmp x12, #64
 ; CHECK-GI-NEXT:    lsr x18, x3, x12
-; CHECK-GI-NEXT:    orr x0, x8, x16
 ; CHECK-GI-NEXT:    csel x9, x9, x11, lo
 ; CHECK-GI-NEXT:    tst x10, #0x7f
-; CHECK-GI-NEXT:    orr x1, x15, x17
 ; CHECK-GI-NEXT:    csel x9, x4, x9, eq
 ; CHECK-GI-NEXT:    cmp x12, #64
+; CHECK-GI-NEXT:    orr x0, x8, x16
 ; CHECK-GI-NEXT:    csel x10, x18, xzr, lo
+; CHECK-GI-NEXT:    orr x1, x15, x17
 ; CHECK-GI-NEXT:    orr x2, x14, x9
 ; CHECK-GI-NEXT:    orr x3, x13, x10
 ; CHECK-GI-NEXT:    ldr x19, [sp], #16 // 8-byte Folded Reload
@@ -2988,65 +2984,65 @@ define <2 x i128> @fshr_v2i128(<2 x i128> %a, <2 x i128> %b, <2 x i128> %c) {
 ; CHECK-GI-NEXT:    extr x14, x1, x0, #63
 ; CHECK-GI-NEXT:    ldr x8, [sp, #16]
 ; CHECK-GI-NEXT:    bic x11, x10, x9
-; CHECK-GI-NEXT:    mvn x16, x9
-; CHECK-GI-NEXT:    and x15, x9, #0x7f
+; CHECK-GI-NEXT:    mvn x15, x9
 ; CHECK-GI-NEXT:    sub x17, x12, x11
 ; CHECK-GI-NEXT:    sub x18, x11, #64
-; CHECK-GI-NEXT:    lsl x0, x14, x11
+; CHECK-GI-NEXT:    lsl x0, x14, x15
 ; CHECK-GI-NEXT:    lsr x17, x13, x17
-; CHECK-GI-NEXT:    lsl x1, x13, x11
+; CHECK-GI-NEXT:    lsl x1, x13, x15
 ; CHECK-GI-NEXT:    lsl x13, x13, x18
 ; CHECK-GI-NEXT:    bic x10, x10, x8
 ; CHECK-GI-NEXT:    lsl x18, x2, #1
 ; CHECK-GI-NEXT:    cmp x11, #64
 ; CHECK-GI-NEXT:    orr x17, x17, x0
 ; CHECK-GI-NEXT:    extr x11, x3, x2, #63
-; CHECK-GI-NEXT:    csel x0, x1, xzr, lo
+; CHECK-GI-NEXT:    mvn x16, x8
 ; CHECK-GI-NEXT:    csel x13, x17, x13, lo
 ; CHECK-GI-NEXT:    sub x17, x12, x10
-; CHECK-GI-NEXT:    tst x16, #0x7f
-; CHECK-GI-NEXT:    sub x16, x10, #64
+; CHECK-GI-NEXT:    csel x0, x1, xzr, lo
+; CHECK-GI-NEXT:    tst x15, #0x7f
+; CHECK-GI-NEXT:    sub x15, x10, #64
 ; CHECK-GI-NEXT:    lsr x17, x18, x17
-; CHECK-GI-NEXT:    lsl x2, x11, x10
-; CHECK-GI-NEXT:    lsl x1, x18, x10
+; CHECK-GI-NEXT:    lsl x2, x11, x16
 ; CHECK-GI-NEXT:    csel x13, x14, x13, eq
-; CHECK-GI-NEXT:    lsl x14, x18, x16
+; CHECK-GI-NEXT:    lsl x14, x18, x15
+; CHECK-GI-NEXT:    lsl x1, x18, x16
 ; CHECK-GI-NEXT:    cmp x10, #64
-; CHECK-GI-NEXT:    mvn x10, x8
-; CHECK-GI-NEXT:    orr x16, x17, x2
+; CHECK-GI-NEXT:    and x10, x9, #0x7f
+; CHECK-GI-NEXT:    orr x15, x17, x2
+; CHECK-GI-NEXT:    lsr x18, x4, x10
+; CHECK-GI-NEXT:    csel x14, x15, x14, lo
+; CHECK-GI-NEXT:    sub x15, x12, x10
 ; CHECK-GI-NEXT:    csel x17, x1, xzr, lo
-; CHECK-GI-NEXT:    csel x14, x16, x14, lo
-; CHECK-GI-NEXT:    tst x10, #0x7f
-; CHECK-GI-NEXT:    sub x10, x12, x15
-; CHECK-GI-NEXT:    sub x16, x15, #64
-; CHECK-GI-NEXT:    lsr x18, x4, x15
-; CHECK-GI-NEXT:    lsl x10, x5, x10
+; CHECK-GI-NEXT:    tst x16, #0x7f
+; CHECK-GI-NEXT:    sub x16, x10, #64
+; CHECK-GI-NEXT:    lsl x15, x5, x15
 ; CHECK-GI-NEXT:    csel x11, x11, x14, eq
 ; CHECK-GI-NEXT:    lsr x14, x5, x16
 ; CHECK-GI-NEXT:    and x1, x8, #0x7f
-; CHECK-GI-NEXT:    cmp x15, #64
-; CHECK-GI-NEXT:    lsr x16, x5, x15
-; CHECK-GI-NEXT:    orr x10, x18, x10
-; CHECK-GI-NEXT:    csel x10, x10, x14, lo
+; CHECK-GI-NEXT:    orr x15, x18, x15
+; CHECK-GI-NEXT:    cmp x10, #64
+; CHECK-GI-NEXT:    lsr x16, x5, x10
+; CHECK-GI-NEXT:    csel x14, x15, x14, lo
 ; CHECK-GI-NEXT:    tst x9, #0x7f
 ; CHECK-GI-NEXT:    sub x9, x12, x1
 ; CHECK-GI-NEXT:    sub x12, x1, #64
-; CHECK-GI-NEXT:    lsr x14, x6, x1
+; CHECK-GI-NEXT:    lsr x15, x6, x1
 ; CHECK-GI-NEXT:    lsl x9, x7, x9
-; CHECK-GI-NEXT:    csel x10, x4, x10, eq
-; CHECK-GI-NEXT:    cmp x15, #64
-; CHECK-GI-NEXT:    lsr x12, x7, x12
-; CHECK-GI-NEXT:    csel x15, x16, xzr, lo
-; CHECK-GI-NEXT:    orr x9, x14, x9
+; CHECK-GI-NEXT:    csel x14, x4, x14, eq
+; CHECK-GI-NEXT:    cmp x10, #64
+; CHECK-GI-NEXT:    lsr x10, x7, x12
+; CHECK-GI-NEXT:    csel x12, x16, xzr, lo
+; CHECK-GI-NEXT:    orr x9, x15, x9
 ; CHECK-GI-NEXT:    cmp x1, #64
-; CHECK-GI-NEXT:    lsr x14, x7, x1
-; CHECK-GI-NEXT:    csel x9, x9, x12, lo
+; CHECK-GI-NEXT:    lsr x15, x7, x1
+; CHECK-GI-NEXT:    csel x9, x9, x10, lo
 ; CHECK-GI-NEXT:    tst x8, #0x7f
 ; CHECK-GI-NEXT:    csel x8, x6, x9, eq
 ; CHECK-GI-NEXT:    cmp x1, #64
-; CHECK-GI-NEXT:    orr x0, x0, x10
-; CHECK-GI-NEXT:    csel x9, x14, xzr, lo
-; CHECK-GI-NEXT:    orr x1, x13, x15
+; CHECK-GI-NEXT:    orr x0, x0, x14
+; CHECK-GI-NEXT:    csel x9, x15, xzr, lo
+; CHECK-GI-NEXT:    orr x1, x13, x12
 ; CHECK-GI-NEXT:    orr x2, x17, x8
 ; CHECK-GI-NEXT:    orr x3, x11, x9
 ; CHECK-GI-NEXT:    ret
diff --git a/llvm/test/CodeGen/AArch64/funnel-shift.ll b/llvm/test/CodeGen/AArch64/funnel-shift.ll
index c4e4d3c7dcd2b..8ac14f53bb4fc 100644
--- a/llvm/test/CodeGen/AArch64/funnel-shift.ll
+++ b/llvm/test/CodeGen/AArch64/funnel-shift.ll
@@ -31,9 +31,8 @@ define i32 @fshl_i32(i32 %x, i32 %y, i32 %z) {
 ; CHECK-GI:       // %bb.0:
 ; CHECK-GI-NEXT:    mov w8, #31 // =0x1f
 ; CHECK-GI-NEXT:    lsr w9, w1, #1
-; CHECK-GI-NEXT:    and w10, w2, #0x1f
+; CHECK-GI-NEXT:    lsl w10, w0, w2
 ; CHECK-GI-NEXT:    bic w8, w8, w2
-; CHECK-GI-NEXT:    lsl w10, w0, w10
 ; CHECK-GI-NEXT:    lsr w8, w9, w8
 ; CHECK-GI-NEXT:    orr w0, w10, w8
 ; CHECK-GI-NEXT:    ret
@@ -55,9 +54,8 @@ define i64 @fshl_i64(i64 %x, i64 %y, i64 %z) {
 ; CHECK-GI:       // %bb.0:
 ; CHECK-GI-NEXT:    mov w8, #63 // =0x3f
 ; CHECK-GI-NEXT:    lsr x9, x1, #1
-; CHECK-GI-NEXT:    and x10, x2, #0x3f
+; CHECK-GI-NEXT:    lsl x10, x0, x2
 ; CHECK-GI-NEXT:    bic x8, x8, x2
-; CHECK-GI-NEXT:    lsl x10, x0, x10
 ; CHECK-GI-NEXT:    lsr x8, x9, x8
 ; CHECK-GI-NEXT:    orr x0, x10, x8
 ; CHECK-GI-NEXT:    ret
@@ -87,22 +85,22 @@ define i128 @fshl_i128(i128 %x, i128 %y, i128 %z) nounwind {
 ; CHECK-GI:       // %bb.0:
 ; CHECK-GI-NEXT:    mov w8, #64 // =0x40
 ; CHECK-GI-NEXT:    and x9, x4, #0x7f
-; CHECK-GI-NEXT:    mov w10, #127 // =0x7f
+; CHECK-GI-NEXT:    lsl x13, x1, x4
 ; CHECK-GI-NEXT:    sub x12, x8, x9
-; CHECK-GI-NEXT:    lsl x13, x1, x9
-; CHECK-GI-NEXT:    bic x10, x10, x4
+; CHECK-GI-NEXT:    mov w10, #127 // =0x7f
+; CHECK-GI-NEXT:    sub x15, x9, #64
 ; CHECK-GI-NEXT:    lsr x12, x0, x12
-; CHECK-GI-NEXT:    sub x14, x9, #64
-; CHECK-GI-NEXT:    lsl x15, x0, x9
+; CHECK-GI-NEXT:    bic x10, x10, x4
 ; CHECK-GI-NEXT:    extr x16, x3, x2, #1
 ; CHECK-GI-NEXT:    cmp x9, #64
+; CHECK-GI-NEXT:    lsl x14, x0, x4
 ; CHECK-GI-NEXT:    sub x8, x8, x10
 ; CHECK-GI-NEXT:    orr x9, x12, x13
 ; CHECK-GI-NEXT:    lsr x12, x3, #1
-; CHECK-GI-NEXT:    lsl x13, x0, x14
-; CHECK-GI-NEXT:    csel x14, x15, xzr, lo
+; CHECK-GI-NEXT:    lsl x13, x0, x15
 ; CHECK-GI-NEXT:    sub x15, x10, #64
 ; CHECK-GI-NEXT:    lsr x17, x16, x10
+; CHECK-GI-NEXT:    csel x14, x14, xzr, lo
 ; CHECK-GI-NEXT:    lsl x8, x12, x8
 ; CHECK-GI-NEXT:    csel x9, x9, x13, lo
 ; CHECK-GI-NEXT:    tst x4, #0x7f
@@ -153,9 +151,8 @@ define i37 @fshl_i37(i37 %x, i37 %y, i37 %z) {
 ; CHECK-GI-NEXT:    mov w9, #36 // =0x24
 ; CHECK-GI-NEXT:    ubfx x10, x1, #1, #36
 ; CHECK-GI-NEXT:    sub x9, x9, x8
-; CHECK-GI-NEXT:    and x8, x8, #0x1fffffffff
-; CHECK-GI-NEXT:    and x9, x9, #0x1fffffffff
 ; CHECK-GI-NEXT:    lsl x8, x0, x8
+; CHECK-GI-NEXT:    and x9, x9, #0x1fffffffff
 ; CHECK-GI-NEXT:    lsr x9, x10, x9
 ; CHECK-GI-NEXT:    orr x0, x8, x9
 ; CHECK-GI-NEXT:    ret
@@ -300,12 +297,11 @@ define i32 @fshr_i32(i32 %x, i32 %y, i32 %z) {
 ;
 ; CHECK-GI-LABEL: fshr_i32:
 ; CHECK-GI:       // %bb.0:
-; CHECK-GI-NEXT:    mov w8, #31 // =0x1f
-; CHECK-GI-NEXT:    lsl w9, w0, #1
-; CHECK-GI-NEXT:    and w10, w2, #0x1f
-; CHECK-GI-NEXT:    bic w8, w8, w2
-; CHECK-GI-NEXT:    lsl w8, w9, w8
-; CHECK-GI-NEXT:    lsr w9, w1, w10
+; CHECK-GI-NEXT:    lsl w8, w0, #1
+; CHECK-GI-NEXT:    and w9, w2, #0x1f
+; CHECK-GI-NEXT:    mvn w10, w2
+; CHECK-GI-NEXT:    lsr w9, w1, w9
+; CHECK-GI-NEXT:    lsl w8, w8, w10
 ; CHECK-GI-NEXT:    orr w0, w8, w9
 ; CHECK-GI-NEXT:    ret
   %f = call i32 @llvm.fshr.i32(i32 %x, i32 %y, i32 %z)
@@ -324,12 +320,11 @@ define i64 @fshr_i64(i64 %x, i64 %y, i64 %z) {
 ;
 ; CHECK-GI-LABEL: fshr_i64:
 ; CHECK-GI:       // %bb.0:
-; CHECK-GI-NEXT:    mov w8, #63 // =0x3f
-; CHECK-GI-NEXT:    lsl x9, x0, #1
-; CHECK-GI-NEXT:    and x10, x2, #0x3f
-; CHECK-GI-NEXT:    bic x8, x8, x2
-; CHECK-GI-NEXT:    lsl x8, x9, x8
-; CHECK-GI-NEXT:    lsr x9, x1, x10
+; CHECK-GI-NEXT:    lsl x8, x0, #1
+; CHECK-GI-NEXT:    and x9, x2, #0x3f
+; CHECK-GI-NEXT:    mvn x10, x2
+; CHECK-GI-NEXT:    lsr x9, x1, x9
+; CHECK-GI-NEXT:    lsl x8, x8, x10
 ; CHECK-GI-NEXT:    orr x0, x8, x9
 ; CHECK-GI-NEXT:    ret
   %f = call i64 @llvm.fshr.i64(i64 %x, i64 %y, i64 %z)
@@ -369,9 +364,8 @@ define i37 @fshr_i37(i37 %x, i37 %y, i37 %z) {
 ; CHECK-GI-NEXT:    lsl x10, x0, #1
 ; CHECK-GI-NEXT:    sub x9, x9, x8
 ; CHECK-GI-NEXT:    and x8, x8, #0x1fffffffff
-; CHECK-GI-NEXT:    and x9, x9, #0x1fffffffff
-; CHECK-GI-NEXT:    lsr x8, x11, x8
 ; CHECK-GI-NEXT:    lsl x9, x10, x9
+; CHECK-GI-NEXT:    lsr x8, x11, x8
 ; CHECK-GI-NEXT:    orr x0, x9, x8
 ; CHECK-GI-NEXT:    ret
   %f = call i37 @llvm.fshr.i37(i37 %x, i37 %y, i37 %z)
@@ -552,13 +546,12 @@ define i32 @or_shl_fshl(i32 %x, i32 %y, i32 %s) {
 ; CHECK-GI-LABEL: or_shl_fshl:
 ; CHECK-GI:       // %bb.0:
 ; CHECK-GI-NEXT:    mov w8, #31 // =0x1f
-; CHECK-GI-NEXT:    and w9, w2, #0x1f
-; CHECK-GI-NEXT:    lsr w10, w1, #1
-; CHECK-GI-NEXT:    lsl w11, w1, w2
+; CHECK-GI-NEXT:    lsr w9, w1, #1
+; CHECK-GI-NEXT:    lsl w10, w1, w2
 ; CHECK-GI-NEXT:    bic w8, w8, w2
-; CHECK-GI-NEXT:    lsl w9, w0, w9
-; CHECK-GI-NEXT:    lsr w8, w10, w8
-; CHECK-GI-NEXT:    orr w9, w9, w11
+; CHECK-GI-NEXT:    lsl w11, w0, w2
+; CHECK-GI-NEXT:    lsr w8, w9, w8
+; CHECK-GI-NEXT:    orr w9, w11, w10
 ; CHECK-GI-NEXT:    orr w0, w9, w8
 ; CHECK-GI-NEXT:    ret
   %shy = shl i32 %y, %s
@@ -595,13 +588,12 @@ define i32 @or_shl_fshl_commute(i32 %x, i32 %y, i32 %s) {
 ; CHECK-GI-LABEL: or_shl_fshl_commute:
 ; CHECK-GI:       // %bb.0:
 ; CHECK-GI-NEXT:    mov w8, #31 // =0x1f
-; CHECK-GI-NEXT:    and w9, w2, #0x1f
-; CHECK-GI-NEXT:    lsr w10, w1, #1
-; CHECK-GI-NEXT:    lsl w11, w1, w2
+; CHECK-GI-NEXT:    lsr w9, w1, #1
+; CHECK-GI-NEXT:    lsl w10, w1, w2
 ; CHECK-GI-NEXT:    bic w8, w8, w2
-; CHECK-GI-NEXT:    lsl w9, w0, w9
-; CHECK-GI-NEXT:    lsr w8, w10, w8
-; CHECK-GI-NEXT:    orr w9, w11, w9
+; CHECK-GI-NEXT:    lsl w11, w0, w2
+; CHECK-GI-NEXT:    lsr w8, w9, w8
+; CHECK-GI-NEXT:    orr w9, w10, w11
 ; CHECK-GI-NEXT:    orr w0, w9, w8
 ; CHECK-GI-NEXT:    ret
   %shy = shl i32 %y, %s
@@ -637,15 +629,14 @@ define i32 @or_lshr_fshr(i32 %x, i32 %y, i32 %s) {
 ;
 ; CHECK-GI-LABEL: or_lshr_fshr:
 ; CHECK-GI:       // %bb.0:
-; CHECK-GI-NEXT:    mov w8, #31 // =0x1f
-; CHECK-GI-NEXT:    and w9, w2, #0x1f
-; CHECK-GI-NEXT:    lsl w10, w1, #1
-; CHECK-GI-NEXT:    lsr w11, w1, w2
-; CHECK-GI-NEXT:    bic w8, w8, w2
-; CHECK-GI-NEXT:    lsr w9, w0, w9
-; CHECK-GI-NEXT:    lsl w8, w10, w8
-; CHECK-GI-NEXT:    orr w9, w9, w11
-; CHECK-GI-NEXT:    orr w0, w8, w9
+; CHECK-GI-NEXT:    and w8, w2, #0x1f
+; CHECK-GI-NEXT:    lsl w9, w1, #1
+; CHECK-GI-NEXT:    lsr w10, w1, w2
+; CHECK-GI-NEXT:    mvn w11, w2
+; CHECK-GI-NEXT:    lsr w8, w0, w8
+; CHECK-GI-NEXT:    lsl w9, w9, w11
+; CHECK-GI-NEXT:    orr w8, w8, w10
+; CHECK-GI-NEXT:    orr w0, w9, w8
 ; CHECK-GI-NEXT:    ret
   %shy = lshr i32 %y, %s
   %fun = call i32 @llvm.fshr.i32(i32 %y, i32 %x, i32 %s)
@@ -679,15 +670,14 @@ define i32 @or_lshr_fshr_commute(i32 %x, i32 %y, i32 %s) {
 ;
 ; CHECK-GI-LABEL: or_lshr_fshr_commute:
 ; CHECK-GI:       // %bb.0:
-; CHECK-GI-NEXT:    mov w8, #31 // =0x1f
-; CHECK-GI-NEXT:    and w9, w2, #0x1f
-; CHECK-GI-NEXT:    lsl w10, w1, #1
-; CHECK-GI-NEXT:    lsr w11, w1, w2
-; CHECK-GI-NEXT:    bic w8, w8, w2
-; CHECK-GI-NEXT:    lsr w9, w0, w9
-; CHECK-GI-NEXT:    lsl w8, w10, w8
-; CHECK-GI-NEXT:    orr w9, w11, w9
-; CHECK-GI-NEXT:    orr w0, w9, w8
+; CHECK-GI-NEXT:    and w8, w2, #0x1f
+; CHECK-GI-NEXT:    lsl w9, w1, #1
+; CHECK-GI-NEXT:    lsr w10, w1, w2
+; CHECK-GI-NEXT:    mvn w11, w2
+; CHECK-GI-NEXT:    lsr w8, w0, w8
+; CHECK-GI-NEXT:    lsl w9, w9, w11
+; CHECK-GI-NEXT:    orr w8, w10, w8
+; CHECK-GI-NEXT:    orr w0, w8, w9
 ; CHECK-GI-NEXT:    ret
   %shy = lshr i32 %y, %s
   %fun = call i32 @llvm.fshr.i32(i32 %y, i32 %x, i32 %s)
@@ -722,9 +712,8 @@ define i32 @or_shl_fshl_simplify(i32 %x, i32 %y, i32 %s) {
 ; CHECK-GI:       // %bb.0:
 ; CHECK-GI-NEXT:    mov w8, #31 // =0x1f
 ; CHECK-GI-NEXT:    lsr w9, w0, #1
-; CHECK-GI-NEXT:    and w10, w2, #0x1f
+; CHECK-GI-NEXT:    lsl w10, w1, w2
 ; CHECK-GI-NEXT:    bic w8, w8, w2
-; CHECK-GI-NEXT:    lsl w10, w1, w10
 ; CHECK-GI-NEXT:    lsr w8, w9, w8
 ; CHECK-GI-NEXT:    orr w0, w10, w8
 ; CHECK-GI-NEXT:    ret
@@ -746,12 +735,11 @@ define i32 @or_lshr_fshr_simplify(i32 %x, i32 %y, i32 %s) {
 ;
 ; CHECK-GI-LABEL: or_lshr_fshr_simplify:
 ; CHECK-GI:       // %bb.0:
-; CHECK-GI-NEXT:    mov w8, #31 // =0x1f
-; CHECK-GI-NEXT:    lsl w9, w0, #1
-; CHECK-GI-NEXT:    and w10, w2, #0x1f
-; CHECK-GI-NEXT:    bic w8, w8, w2
-; CHECK-GI-NEXT:    lsl w8, w9, w8
-; CHECK-GI-NEXT:    lsr w9, w1, w10
+; CHECK-GI-NEXT:    lsl w8, w0, #1
+; CHECK-GI-NEXT:    and w9, w2, #0x1f
+; CHECK-GI-NEXT:    mvn w10, w2
+; CHECK-GI-NEXT:    lsr w9, w1, w9
+; CHECK-GI-NEXT:    lsl w8, w8, w10
 ; CHECK-GI-NEXT:    orr w0, w8, w9
 ; CHECK-GI-NEXT:    ret
   %shy = lshr i32 %y, %s
diff --git a/llvm/test/CodeGen/AArch64/hoist-and-by-const-from-shl-in-eqcmp-zero.ll b/llvm/test/CodeGen/AArch64/hoist-and-by-const-from-shl-in-eqcmp-zero.ll
index e1d5da3d37922..022d80d30ea60 100644
--- a/llvm/test/CodeGen/AArch64/hoist-and-by-const-from-shl-in-eqcmp-zero.ll
+++ b/llvm/test/CodeGen/AArch64/hoist-and-by-const-from-shl-in-eqcmp-zero.ll
@@ -25,8 +25,7 @@ define i1 @scalar_i8_signbit_eq(i8 %x, i8 %y) nounwind {
 ; CHECK-GI-LABEL: scalar_i8_signbit_eq:
 ; CHECK-GI:       // %bb.0:
 ; CHECK-GI-NEXT:    mov w8, #-128 // =0xffffff80
-; CHECK-GI-NEXT:    and w9, w1, #0xff
-; CHECK-GI-NEXT:    lsl w8, w8, w9
+; CHECK-GI-NEXT:    lsl w8, w8, w1
 ; CHECK-GI-NEXT:    and w8, w8, w0
 ; CHECK-GI-NEXT:    tst w8, #0xff
 ; CHECK-GI-NEXT:    cset w0, eq
@@ -49,8 +48,7 @@ define i1 @scalar_i8_lowestbit_eq(i8 %x, i8 %y) nounwind {
 ; CHECK-GI-LABEL: scalar_i8_lowestbit_eq:
 ; CHECK-GI:       // %bb.0:
 ; CHECK-GI-NEXT:    mov w8, #1 // =0x1
-; CHECK-GI-NEXT:    and w9, w1, #0xff
-; CHECK-GI-NEXT:    lsl w8, w8, w9
+; CHECK-GI-NEXT:    lsl w8, w8, w1
 ; CHECK-GI-NEXT:    and w8, w8, w0
 ; CHECK-GI-NEXT:    tst w8, #0xff
 ; CHECK-GI-NEXT:    cset w0, eq
@@ -73,8 +71,7 @@ define i1 @scalar_i8_bitsinmiddle_eq(i8 %x, i8 %y) nounwind {
 ; CHECK-GI-LABEL: scalar_i8_bitsinmiddle_eq:
 ; CHECK-GI:       // %bb.0:
 ; CHECK-GI-NEXT:    mov w8, #24 // =0x18
-; CHECK-GI-NEXT:    and w9, w1, #0xff
-; CHECK-GI-NEXT:    lsl w8, w8, w9
+; CHECK-GI-NEXT:    lsl w8, w8, w1
 ; CHECK-GI-NEXT:    and w8, w8, w0
 ; CHECK-GI-NEXT:    tst w8, #0xff
 ; CHECK-GI-NEXT:    cset w0, eq
@@ -99,8 +96,7 @@ define i1 @scalar_i16_signbit_eq(i16 %x, i16 %y) nounwind {
 ; CHECK-GI-LABEL: scalar_i16_signbit_eq:
 ; CHECK-GI:       // %bb.0:
 ; CHECK-GI-NEXT:    mov w8, #-32768 // =0xffff8000
-; CHECK-GI-NEXT:    and w9, w1, #0xffff
-; CHECK-GI-NEXT:    lsl w8, w8, w9
+; CHECK-GI-NEXT:    lsl w8, w8, w1
 ; CHECK-GI-NEXT:    and w8, w8, w0
 ; CHECK-GI-NEXT:    tst w8, #0xffff
 ; CHECK-GI-NEXT:    cset w0, eq
@@ -123,8 +119,7 @@ define i1 @scalar_i16_lowestbit_eq(i16 %x, i16 %y) nounwind {
 ; CHECK-GI-LABEL: scalar_i16_lowestbit_eq:
 ; CHECK-GI:       // %bb.0:
 ; CHECK-GI-NEXT:    mov w8, #1 // =0x1
-; CHECK-GI-NEXT:    and w9, w1, #0xffff
-; CHECK-GI-NEXT:    lsl w8, w8, w9
+; CHECK-GI-NEXT:    lsl w8, w8, w1
 ; CHECK-GI-NEXT:    and w8, w8, w0
 ; CHECK-GI-NEXT:    tst w8, #0xffff
 ; CHECK-GI-NEXT:    cset w0, eq
@@ -147,8 +142,7 @@ define i1 @scalar_i16_bitsinmiddle_eq(i16 %x, i16 %y) nounwind {
 ; CHECK-GI-LABEL: scalar_i16_bitsinmiddle_eq:
 ; CHECK-GI:       // %bb.0:
 ; CHECK-GI-NEXT:    mov w8, #4080 // =0xff0
-; CHECK-GI-NEXT:    and w9, w1, #0xffff
-; CHECK-GI-NEXT:    lsl w8, w8, w9
+; CHECK-GI-NEXT:    lsl w8, w8, w1
 ; CHECK-GI-NEXT:    and w8, w8, w0
 ; CHECK-GI-NEXT:    tst w8, #0xffff
 ; CHECK-GI-NEXT:    cset w0, eq
@@ -402,8 +396,7 @@ define i1 @scalar_i8_signbit_ne(i8 %x, i8 %y) nounwind {
 ; CHECK-GI-LABEL: scalar_i8_signbit_ne:
 ; CHECK-GI:       // %bb.0:
 ; CHECK-GI-NEXT:    mov w8, #-128 // =0xffffff80
-; CHECK-GI-NEXT:    and w9, w1, #0xff
-; CHECK-GI-NEXT:    lsl w8, w8, w9
+; CHECK-GI-NEXT:    lsl w8, w8, w1
 ; CHECK-GI-NEXT:    and w8, w8, w0
 ; CHECK-GI-NEXT:    tst w8, #0xff
 ; CHECK-GI-NEXT:    cset w0, ne
@@ -460,8 +453,7 @@ define i1 @scalar_i8_bitsinmiddle_slt(i8 %x, i8 %y) nounwind {
 ; CHECK-GI-LABEL: scalar_i8_bitsinmiddle_slt:
 ; CHECK-GI:       // %bb.0:
 ; CHECK-GI-NEXT:    mov w8, #24 // =0x18
-; CHECK-GI-NEXT:    and w9, w1, #0xff
-; CHECK-GI-NEXT:    lsl w8, w8, w9
+; CHECK-GI-NEXT:    lsl w8, w8, w1
 ; CHECK-GI-NEXT:    and w8, w8, w0
 ; CHECK-GI-NEXT:    sxtb w8, w8
 ; CHECK-GI-NEXT:    cmp w8, #0
diff --git a/llvm/test/CodeGen/AArch64/select_const.ll b/llvm/test/CodeGen/AArch64/select_const.ll
index daa9971dbcd58..5a5ba9d1689b9 100644
--- a/llvm/test/CodeGen/AArch64/select_const.ll
+++ b/llvm/test/CodeGen/AArch64/select_const.ll
@@ -672,7 +672,6 @@ define i8 @shl_constant_sel_constants(i1 %cond) {
 ; CHECK-GI-NEXT:    sbfx w9, w0, #0, #1
 ; CHECK-GI-NEXT:    mov w8, #1 // =0x1
 ; CHECK-GI-NEXT:    add w9, w9, #3
-; CHECK-GI-NEXT:    and w9, w9, #0xff
 ; CHECK-GI-NEXT:    lsl w0, w8, w9
 ; CHECK-GI-NEXT:    ret
   %sel = select i1 %cond, i8 2, i8 3
diff --git a/llvm/test/CodeGen/AArch64/shift.ll b/llvm/test/CodeGen/AArch64/shift.ll
index 574afd32eecc0..526e781e117f4 100644
--- a/llvm/test/CodeGen/AArch64/shift.ll
+++ b/llvm/test/CodeGen/AArch64/shift.ll
@@ -19,31 +19,19 @@ define i1 @shl_i1(i1 %0, i1 %1){
 }
 
 define i8 @shl_i8(i8 %0, i8 %1){
-; CHECK-SD-LABEL: shl_i8:
-; CHECK-SD:       // %bb.0:
-; CHECK-SD-NEXT:    lsl w0, w0, w1
-; CHECK-SD-NEXT:    ret
-;
-; CHECK-GI-LABEL: shl_i8:
-; CHECK-GI:       // %bb.0:
-; CHECK-GI-NEXT:    and w8, w1, #0xff
-; CHECK-GI-NEXT:    lsl w0, w0, w8
-; CHECK-GI-NEXT:    ret
+; CHECK-LABEL: shl_i8:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    lsl w0, w0, w1
+; CHECK-NEXT:    ret
     %3 = shl i8 %0, %1
     ret i8 %3
 }
 
 define i16 @shl_i16(i16 %0, i16 %1){
-; CHECK-SD-LABEL: shl_i16:
-; CHECK-SD:       // %bb.0:
-; CHECK-SD-NEXT:    lsl w0, w0, w1
-; CHECK-SD-NEXT:    ret
-;
-; CHECK-GI-LABEL: shl_i16:
-; CHECK-GI:       // %bb.0:
-; CHECK-GI-NEXT:    and w8, w1, #0xffff
-; CHECK-GI-NEXT:    lsl w0, w0, w8
-; CHECK-GI-NEXT:    ret
+; CHECK-LABEL: shl_i16:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    lsl w0, w0, w1
+; CHECK-NEXT:    ret
     %3 = shl i16 %0, %1
     ret i16 %3
 }



More information about the llvm-commits mailing list