1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -S -instcombine < %s | FileCheck %s --check-prefixes=CHECK,LITTLE 3; RUN: opt -S -instcombine -data-layout="E" < %s | FileCheck %s --check-prefixes=CHECK,BIG 4 5define i8 @load_smaller_int(i16* %p) { 6; LITTLE-LABEL: @load_smaller_int( 7; LITTLE-NEXT: store i16 258, i16* [[P:%.*]], align 2 8; LITTLE-NEXT: ret i8 2 9; 10; BIG-LABEL: @load_smaller_int( 11; BIG-NEXT: store i16 258, i16* [[P:%.*]], align 2 12; BIG-NEXT: ret i8 1 13; 14 store i16 258, i16* %p 15 %p2 = bitcast i16* %p to i8* 16 %load = load i8, i8* %p2 17 ret i8 %load 18} 19 20; This case can *not* be forwarded, as we only see part of the stored value. 21define i32 @load_larger_int(i16* %p) { 22; CHECK-LABEL: @load_larger_int( 23; CHECK-NEXT: store i16 258, i16* [[P:%.*]], align 2 24; CHECK-NEXT: [[P2:%.*]] = bitcast i16* [[P]] to i32* 25; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[P2]], align 4 26; CHECK-NEXT: ret i32 [[LOAD]] 27; 28 store i16 258, i16* %p 29 %p2 = bitcast i16* %p to i32* 30 %load = load i32, i32* %p2 31 ret i32 %load 32} 33 34define i32 @vec_store_load_first(i32* %p) { 35; CHECK-LABEL: @vec_store_load_first( 36; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>* 37; CHECK-NEXT: store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8 38; CHECK-NEXT: ret i32 1 39; 40 %p2 = bitcast i32* %p to <2 x i32>* 41 store <2 x i32> <i32 1, i32 2>, <2 x i32>* %p2 42 %load = load i32, i32* %p 43 ret i32 %load 44} 45 46define i17 @vec_store_load_first_odd_size(i17* %p) { 47; CHECK-LABEL: @vec_store_load_first_odd_size( 48; CHECK-NEXT: [[P2:%.*]] = bitcast i17* [[P:%.*]] to <2 x i17>* 49; CHECK-NEXT: store <2 x i17> <i17 1, i17 2>, <2 x i17>* [[P2]], align 8 50; CHECK-NEXT: ret i17 1 51; 52 %p2 = bitcast i17* %p to <2 x i17>* 53 store <2 x i17> <i17 1, i17 2>, <2 x i17>* %p2 54 %load = load i17, i17* %p 55 ret i17 %load 56} 57 58define i32 @vec_store_load_first_constexpr(i32* %p) { 59; CHECK-LABEL: @vec_store_load_first_constexpr( 60; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>* 61; CHECK-NEXT: store <2 x i32> bitcast (i64 ptrtoint (i32 (i32*)* @vec_store_load_first to i64) to <2 x i32>), <2 x i32>* [[P2]], align 8 62; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[P]], align 4 63; CHECK-NEXT: ret i32 [[LOAD]] 64; 65 %p2 = bitcast i32* %p to <2 x i32>* 66 store <2 x i32> bitcast (i64 ptrtoint (i32 (i32*)* @vec_store_load_first to i64) to <2 x i32>), <2 x i32>* %p2, align 8 67 %load = load i32, i32* %p, align 4 68 ret i32 %load 69} 70 71define i32 @vec_store_load_second(i32* %p) { 72; CHECK-LABEL: @vec_store_load_second( 73; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>* 74; CHECK-NEXT: store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8 75; CHECK-NEXT: [[P3:%.*]] = getelementptr i32, i32* [[P]], i64 1 76; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[P3]], align 4 77; CHECK-NEXT: ret i32 [[LOAD]] 78; 79 %p2 = bitcast i32* %p to <2 x i32>* 80 store <2 x i32> <i32 1, i32 2>, <2 x i32>* %p2 81 %p3 = getelementptr i32, i32* %p, i64 1 82 %load = load i32, i32* %p3 83 ret i32 %load 84} 85 86define i64 @vec_store_load_whole(i32* %p) { 87; LITTLE-LABEL: @vec_store_load_whole( 88; LITTLE-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>* 89; LITTLE-NEXT: store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8 90; LITTLE-NEXT: ret i64 8589934593 91; 92; BIG-LABEL: @vec_store_load_whole( 93; BIG-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>* 94; BIG-NEXT: store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8 95; BIG-NEXT: ret i64 4294967298 96; 97 %p2 = bitcast i32* %p to <2 x i32>* 98 store <2 x i32> <i32 1, i32 2>, <2 x i32>* %p2 99 %p3 = bitcast i32* %p to i64* 100 %load = load i64, i64* %p3 101 ret i64 %load 102} 103 104define i32 @vec_store_load_overlap(i32* %p) { 105; CHECK-LABEL: @vec_store_load_overlap( 106; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>* 107; CHECK-NEXT: store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8 108; CHECK-NEXT: [[P3:%.*]] = bitcast i32* [[P]] to i8* 109; CHECK-NEXT: [[P4:%.*]] = getelementptr i8, i8* [[P3]], i64 2 110; CHECK-NEXT: [[P5:%.*]] = bitcast i8* [[P4]] to i32* 111; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[P5]], align 2 112; CHECK-NEXT: ret i32 [[LOAD]] 113; 114 %p2 = bitcast i32* %p to <2 x i32>* 115 store <2 x i32> <i32 1, i32 2>, <2 x i32>* %p2 116 %p3 = bitcast i32* %p to i8* 117 %p4 = getelementptr i8, i8* %p3, i64 2 118 %p5 = bitcast i8* %p4 to i32* 119 %load = load i32, i32* %p5, align 2 120 ret i32 %load 121} 122