Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -load-combine -instcombine -S | FileCheck %s |
| 2 | |
| 3 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 4 | target triple = "x86_64-unknown-linux-gnu" |
| 5 | |
| 6 | ; Combine read from char* idiom. |
| 7 | define i64 @LoadU64_x64_0(i64* %pData) { |
| 8 | %1 = bitcast i64* %pData to i8* |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 9 | %2 = load i8, i8* %1, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 10 | %3 = zext i8 %2 to i64 |
| 11 | %4 = shl nuw i64 %3, 56 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 12 | %5 = getelementptr inbounds i8, i8* %1, i64 1 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 13 | %6 = load i8, i8* %5, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 14 | %7 = zext i8 %6 to i64 |
| 15 | %8 = shl nuw nsw i64 %7, 48 |
| 16 | %9 = or i64 %8, %4 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 17 | %10 = getelementptr inbounds i8, i8* %1, i64 2 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 18 | %11 = load i8, i8* %10, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 19 | %12 = zext i8 %11 to i64 |
| 20 | %13 = shl nuw nsw i64 %12, 40 |
| 21 | %14 = or i64 %9, %13 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 22 | %15 = getelementptr inbounds i8, i8* %1, i64 3 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 23 | %16 = load i8, i8* %15, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 24 | %17 = zext i8 %16 to i64 |
| 25 | %18 = shl nuw nsw i64 %17, 32 |
| 26 | %19 = or i64 %14, %18 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 27 | %20 = getelementptr inbounds i8, i8* %1, i64 4 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 28 | %21 = load i8, i8* %20, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 29 | %22 = zext i8 %21 to i64 |
| 30 | %23 = shl nuw nsw i64 %22, 24 |
| 31 | %24 = or i64 %19, %23 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 32 | %25 = getelementptr inbounds i8, i8* %1, i64 5 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 33 | %26 = load i8, i8* %25, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 34 | %27 = zext i8 %26 to i64 |
| 35 | %28 = shl nuw nsw i64 %27, 16 |
| 36 | %29 = or i64 %24, %28 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 37 | %30 = getelementptr inbounds i8, i8* %1, i64 6 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 38 | %31 = load i8, i8* %30, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 39 | %32 = zext i8 %31 to i64 |
| 40 | %33 = shl nuw nsw i64 %32, 8 |
| 41 | %34 = or i64 %29, %33 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 42 | %35 = getelementptr inbounds i8, i8* %1, i64 7 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 43 | %36 = load i8, i8* %35, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 44 | %37 = zext i8 %36 to i64 |
| 45 | %38 = or i64 %34, %37 |
| 46 | ret i64 %38 |
| 47 | ; CHECK-LABEL: @LoadU64_x64_0( |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 48 | ; CHECK: load i64, i64* %{{.*}}, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 49 | ; CHECK-NOT: load |
| 50 | } |
| 51 | |
| 52 | ; Combine simple adjacent loads. |
| 53 | define i32 @"2xi16_i32"(i16* %x) { |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 54 | %1 = load i16, i16* %x, align 2 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 55 | %2 = getelementptr inbounds i16, i16* %x, i64 1 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 56 | %3 = load i16, i16* %2, align 2 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 57 | %4 = zext i16 %3 to i32 |
| 58 | %5 = shl nuw i32 %4, 16 |
| 59 | %6 = zext i16 %1 to i32 |
| 60 | %7 = or i32 %5, %6 |
| 61 | ret i32 %7 |
| 62 | ; CHECK-LABEL: @"2xi16_i32"( |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 63 | ; CHECK: load i32, i32* %{{.*}}, align 2 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 64 | ; CHECK-NOT: load |
| 65 | } |
| 66 | |
| 67 | ; Don't combine loads across stores. |
| 68 | define i32 @"2xi16_i32_store"(i16* %x, i16* %y) { |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 69 | %1 = load i16, i16* %x, align 2 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 70 | store i16 0, i16* %y, align 2 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 71 | %2 = getelementptr inbounds i16, i16* %x, i64 1 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 72 | %3 = load i16, i16* %2, align 2 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 73 | %4 = zext i16 %3 to i32 |
| 74 | %5 = shl nuw i32 %4, 16 |
| 75 | %6 = zext i16 %1 to i32 |
| 76 | %7 = or i32 %5, %6 |
| 77 | ret i32 %7 |
| 78 | ; CHECK-LABEL: @"2xi16_i32_store"( |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 79 | ; CHECK: load i16, i16* %{{.*}}, align 2 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 80 | ; CHECK: store |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 81 | ; CHECK: load i16, i16* %{{.*}}, align 2 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | ; Don't combine loads with a gap. |
| 85 | define i32 @"2xi16_i32_gap"(i16* %x) { |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 86 | %1 = load i16, i16* %x, align 2 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 87 | %2 = getelementptr inbounds i16, i16* %x, i64 2 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 88 | %3 = load i16, i16* %2, align 2 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 89 | %4 = zext i16 %3 to i32 |
| 90 | %5 = shl nuw i32 %4, 16 |
| 91 | %6 = zext i16 %1 to i32 |
| 92 | %7 = or i32 %5, %6 |
| 93 | ret i32 %7 |
| 94 | ; CHECK-LABEL: @"2xi16_i32_gap"( |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 95 | ; CHECK: load i16, i16* %{{.*}}, align 2 |
| 96 | ; CHECK: load i16, i16* %{{.*}}, align 2 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | ; Combine out of order loads. |
| 100 | define i32 @"2xi16_i32_order"(i16* %x) { |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 101 | %1 = getelementptr inbounds i16, i16* %x, i64 1 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 102 | %2 = load i16, i16* %1, align 2 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 103 | %3 = zext i16 %2 to i32 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 104 | %4 = load i16, i16* %x, align 2 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 105 | %5 = shl nuw i32 %3, 16 |
| 106 | %6 = zext i16 %4 to i32 |
| 107 | %7 = or i32 %5, %6 |
| 108 | ret i32 %7 |
| 109 | ; CHECK-LABEL: @"2xi16_i32_order"( |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 110 | ; CHECK: load i32, i32* %{{.*}}, align 2 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 111 | ; CHECK-NOT: load |
| 112 | } |
| 113 | |
| 114 | ; Overlapping loads. |
| 115 | define i32 @"2xi16_i32_overlap"(i8* %x) { |
| 116 | %1 = bitcast i8* %x to i16* |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 117 | %2 = load i16, i16* %1, align 2 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 118 | %3 = getelementptr inbounds i8, i8* %x, i64 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 119 | %4 = bitcast i8* %3 to i16* |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 120 | %5 = load i16, i16* %4, align 2 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 121 | %6 = zext i16 %5 to i32 |
| 122 | %7 = shl nuw i32 %6, 16 |
| 123 | %8 = zext i16 %2 to i32 |
| 124 | %9 = or i32 %7, %8 |
| 125 | ret i32 %9 |
| 126 | ; CHECK-LABEL: @"2xi16_i32_overlap"( |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 127 | ; CHECK: load i16, i16* %{{.*}}, align 2 |
| 128 | ; CHECK: load i16, i16* %{{.*}}, align 2 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | ; Combine valid alignments. |
| 132 | define i64 @"2xi16_i64_align"(i8* %x) { |
| 133 | %1 = bitcast i8* %x to i32* |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 134 | %2 = load i32, i32* %1, align 4 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 135 | %3 = getelementptr inbounds i8, i8* %x, i64 4 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 136 | %4 = bitcast i8* %3 to i16* |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 137 | %5 = load i16, i16* %4, align 2 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 138 | %6 = getelementptr inbounds i8, i8* %x, i64 6 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 139 | %7 = bitcast i8* %6 to i16* |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 140 | %8 = load i16, i16* %7, align 2 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 141 | %9 = zext i16 %8 to i64 |
| 142 | %10 = shl nuw i64 %9, 48 |
| 143 | %11 = zext i16 %5 to i64 |
| 144 | %12 = shl nuw nsw i64 %11, 32 |
| 145 | %13 = zext i32 %2 to i64 |
| 146 | %14 = or i64 %12, %13 |
| 147 | %15 = or i64 %14, %10 |
| 148 | ret i64 %15 |
| 149 | ; CHECK-LABEL: @"2xi16_i64_align"( |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 150 | ; CHECK: load i64, i64* %{{.*}}, align 4 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | ; Non power of two. |
| 154 | define i64 @"2xi16_i64_npo2"(i8* %x) { |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 155 | %1 = load i8, i8* %x, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 156 | %2 = zext i8 %1 to i64 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 157 | %3 = getelementptr inbounds i8, i8* %x, i64 1 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 158 | %4 = load i8, i8* %3, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 159 | %5 = zext i8 %4 to i64 |
| 160 | %6 = shl nuw nsw i64 %5, 8 |
| 161 | %7 = or i64 %6, %2 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 162 | %8 = getelementptr inbounds i8, i8* %x, i64 2 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 163 | %9 = load i8, i8* %8, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 164 | %10 = zext i8 %9 to i64 |
| 165 | %11 = shl nuw nsw i64 %10, 16 |
| 166 | %12 = or i64 %11, %7 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 167 | %13 = getelementptr inbounds i8, i8* %x, i64 3 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 168 | %14 = load i8, i8* %13, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 169 | %15 = zext i8 %14 to i64 |
| 170 | %16 = shl nuw nsw i64 %15, 24 |
| 171 | %17 = or i64 %16, %12 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 172 | %18 = getelementptr inbounds i8, i8* %x, i64 4 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 173 | %19 = load i8, i8* %18, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 174 | %20 = zext i8 %19 to i64 |
| 175 | %21 = shl nuw nsw i64 %20, 32 |
| 176 | %22 = or i64 %21, %17 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 177 | %23 = getelementptr inbounds i8, i8* %x, i64 5 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 178 | %24 = load i8, i8* %23, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 179 | %25 = zext i8 %24 to i64 |
| 180 | %26 = shl nuw nsw i64 %25, 40 |
| 181 | %27 = or i64 %26, %22 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 182 | %28 = getelementptr inbounds i8, i8* %x, i64 6 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 183 | %29 = load i8, i8* %28, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 184 | %30 = zext i8 %29 to i64 |
| 185 | %31 = shl nuw nsw i64 %30, 48 |
| 186 | %32 = or i64 %31, %27 |
| 187 | ret i64 %32 |
| 188 | ; CHECK-LABEL: @"2xi16_i64_npo2"( |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 189 | ; CHECK: load i32, i32* %{{.*}}, align 1 |
Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 190 | } |