1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker 3*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 4*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-unknown-linux-gnu" 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Worker%structTy = type { i8, i32, i32 } 7*9880d681SAndroid Build Coastguard Worker 8*9880d681SAndroid Build Coastguard Worker@e = common global %structTy zeroinitializer, align 4 9*9880d681SAndroid Build Coastguard Worker 10*9880d681SAndroid Build Coastguard Worker;; Ensure that MergeConsecutiveStores doesn't incorrectly reorder 11*9880d681SAndroid Build Coastguard Worker;; store operations. The first test stores in increasing address 12*9880d681SAndroid Build Coastguard Worker;; order, the second in decreasing -- but in both cases should have 13*9880d681SAndroid Build Coastguard Worker;; the same result in memory in the end. 14*9880d681SAndroid Build Coastguard Worker 15*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: redundant_stores_merging: 16*9880d681SAndroid Build Coastguard Worker; CHECK: movl $123, e+8(%rip) 17*9880d681SAndroid Build Coastguard Worker; CHECK: movabsq $1958505086977, %rax 18*9880d681SAndroid Build Coastguard Worker; CHECK: movq %rax, e+4(%rip) 19*9880d681SAndroid Build Coastguard Workerdefine void @redundant_stores_merging() { 20*9880d681SAndroid Build Coastguard Workerentry: 21*9880d681SAndroid Build Coastguard Worker store i32 1, i32* getelementptr inbounds (%structTy, %structTy* @e, i64 0, i32 1), align 4 22*9880d681SAndroid Build Coastguard Worker store i32 123, i32* getelementptr inbounds (%structTy, %structTy* @e, i64 0, i32 2), align 4 23*9880d681SAndroid Build Coastguard Worker store i32 456, i32* getelementptr inbounds (%structTy, %structTy* @e, i64 0, i32 2), align 4 24*9880d681SAndroid Build Coastguard Worker ret void 25*9880d681SAndroid Build Coastguard Worker} 26*9880d681SAndroid Build Coastguard Worker 27*9880d681SAndroid Build Coastguard Worker;; This variant tests PR25154. 28*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: redundant_stores_merging_reverse: 29*9880d681SAndroid Build Coastguard Worker; CHECK: movl $123, e+8(%rip) 30*9880d681SAndroid Build Coastguard Worker; CHECK: movabsq $1958505086977, %rax 31*9880d681SAndroid Build Coastguard Worker; CHECK: movq %rax, e+4(%rip) 32*9880d681SAndroid Build Coastguard Workerdefine void @redundant_stores_merging_reverse() { 33*9880d681SAndroid Build Coastguard Workerentry: 34*9880d681SAndroid Build Coastguard Worker store i32 123, i32* getelementptr inbounds (%structTy, %structTy* @e, i64 0, i32 2), align 4 35*9880d681SAndroid Build Coastguard Worker store i32 456, i32* getelementptr inbounds (%structTy, %structTy* @e, i64 0, i32 2), align 4 36*9880d681SAndroid Build Coastguard Worker store i32 1, i32* getelementptr inbounds (%structTy, %structTy* @e, i64 0, i32 1), align 4 37*9880d681SAndroid Build Coastguard Worker ret void 38*9880d681SAndroid Build Coastguard Worker} 39*9880d681SAndroid Build Coastguard Worker 40*9880d681SAndroid Build Coastguard Worker@b = common global [8 x i8] zeroinitializer, align 2 41*9880d681SAndroid Build Coastguard Worker 42*9880d681SAndroid Build Coastguard Worker;; The 2-byte store to offset 3 overlaps the 2-byte store to offset 2; 43*9880d681SAndroid Build Coastguard Worker;; these must not be reordered in MergeConsecutiveStores such that the 44*9880d681SAndroid Build Coastguard Worker;; store to 3 comes first (e.g. by merging the stores to 0 and 2 into 45*9880d681SAndroid Build Coastguard Worker;; a movl, after the store to 3). 46*9880d681SAndroid Build Coastguard Worker 47*9880d681SAndroid Build Coastguard Worker;; CHECK-LABEL: overlapping_stores_merging: 48*9880d681SAndroid Build Coastguard Worker;; CHECK: movw $0, b+2(%rip) 49*9880d681SAndroid Build Coastguard Worker;; CHECK: movw $2, b+3(%rip) 50*9880d681SAndroid Build Coastguard Worker;; CHECK: movw $1, b(%rip) 51*9880d681SAndroid Build Coastguard Workerdefine void @overlapping_stores_merging() { 52*9880d681SAndroid Build Coastguard Workerentry: 53*9880d681SAndroid Build Coastguard Worker store i16 0, i16* bitcast (i8* getelementptr inbounds ([8 x i8], [8 x i8]* @b, i64 0, i64 2) to i16*), align 2 54*9880d681SAndroid Build Coastguard Worker store i16 2, i16* bitcast (i8* getelementptr inbounds ([8 x i8], [8 x i8]* @b, i64 0, i64 3) to i16*), align 1 55*9880d681SAndroid Build Coastguard Worker store i16 1, i16* bitcast (i8* getelementptr inbounds ([8 x i8], [8 x i8]* @b, i64 0, i64 0) to i16*), align 2 56*9880d681SAndroid Build Coastguard Worker ret void 57*9880d681SAndroid Build Coastguard Worker} 58