1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: opt < %s -loop-reduce -mtriple=x86_64 -S | FileCheck %s -check-prefix=INSN
3 ; RUN: opt < %s -loop-reduce -mtriple=x86_64 -lsr-insns-cost=false -S | FileCheck %s -check-prefix=REGS
4 ; RUN: llc < %s -O2 -mtriple=x86_64-unknown-unknown -lsr-insns-cost | FileCheck %s
6 ; OPT test checks that LSR optimize compare for static counter to compare with 0.
8 ; LLC test checks that LSR optimize compare for static counter.
9 ; That means that instead of creating the following:
10 ; movl %ecx, (%rdx,%rax,4)
13 ; LSR should optimize out cmp:
14 ; movl %ecx, 4096(%rdx,%rax)
17 ; movl %ecx, 4096(%rdx,%rax,4)
20 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
22 define void @foo(ptr nocapture readonly %x, ptr nocapture readonly %y, ptr nocapture %q) {
25 ; INSN-NEXT: br label [[FOR_BODY:%.*]]
26 ; INSN: for.cond.cleanup:
29 ; INSN-NEXT: [[LSR_IV:%.*]] = phi i64 [ [[LSR_IV_NEXT:%.*]], [[FOR_BODY]] ], [ -4096, [[ENTRY:%.*]] ]
30 ; INSN-NEXT: [[SCEVGEP4:%.*]] = getelementptr i8, ptr [[X:%.*]], i64 [[LSR_IV]]
31 ; INSN-NEXT: [[SCEVGEP5:%.*]] = getelementptr i8, ptr [[SCEVGEP4]], i64 4096
32 ; INSN-NEXT: [[TMP:%.*]] = load i32, ptr [[SCEVGEP5]], align 4
33 ; INSN-NEXT: [[SCEVGEP2:%.*]] = getelementptr i8, ptr [[Y:%.*]], i64 [[LSR_IV]]
34 ; INSN-NEXT: [[SCEVGEP3:%.*]] = getelementptr i8, ptr [[SCEVGEP2]], i64 4096
35 ; INSN-NEXT: [[TMP1:%.*]] = load i32, ptr [[SCEVGEP3]], align 4
36 ; INSN-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP1]], [[TMP]]
37 ; INSN-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[Q:%.*]], i64 [[LSR_IV]]
38 ; INSN-NEXT: [[SCEVGEP1:%.*]] = getelementptr i8, ptr [[SCEVGEP]], i64 4096
39 ; INSN-NEXT: store i32 [[ADD]], ptr [[SCEVGEP1]], align 4
40 ; INSN-NEXT: [[LSR_IV_NEXT]] = add nsw i64 [[LSR_IV]], 4
41 ; INSN-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[LSR_IV_NEXT]], 0
42 ; INSN-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]]
46 ; REGS-NEXT: br label [[FOR_BODY:%.*]]
47 ; REGS: for.cond.cleanup:
50 ; REGS-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
51 ; REGS-NEXT: [[TMP0:%.*]] = shl nuw nsw i64 [[INDVARS_IV]], 2
52 ; REGS-NEXT: [[SCEVGEP2:%.*]] = getelementptr i8, ptr [[X:%.*]], i64 [[TMP0]]
53 ; REGS-NEXT: [[TMP:%.*]] = load i32, ptr [[SCEVGEP2]], align 4
54 ; REGS-NEXT: [[TMP1:%.*]] = shl nuw nsw i64 [[INDVARS_IV]], 2
55 ; REGS-NEXT: [[SCEVGEP1:%.*]] = getelementptr i8, ptr [[Y:%.*]], i64 [[TMP1]]
56 ; REGS-NEXT: [[TMP1:%.*]] = load i32, ptr [[SCEVGEP1]], align 4
57 ; REGS-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP1]], [[TMP]]
58 ; REGS-NEXT: [[TMP2:%.*]] = shl nuw nsw i64 [[INDVARS_IV]], 2
59 ; REGS-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[Q:%.*]], i64 [[TMP2]]
60 ; REGS-NEXT: store i32 [[ADD]], ptr [[SCEVGEP]], align 4
61 ; REGS-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
62 ; REGS-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 1024
63 ; REGS-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]]
66 ; CHECK: # %bb.0: # %entry
67 ; CHECK-NEXT: movq $-4096, %rax # imm = 0xF000
68 ; CHECK-NEXT: .p2align 4
69 ; CHECK-NEXT: .LBB0_1: # %for.body
70 ; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
71 ; CHECK-NEXT: movl 4096(%rsi,%rax), %ecx
72 ; CHECK-NEXT: addl 4096(%rdi,%rax), %ecx
73 ; CHECK-NEXT: movl %ecx, 4096(%rdx,%rax)
74 ; CHECK-NEXT: addq $4, %rax
75 ; CHECK-NEXT: jne .LBB0_1
76 ; CHECK-NEXT: # %bb.2: # %for.cond.cleanup
81 for.cond.cleanup: ; preds = %for.body
84 for.body: ; preds = %for.body, %entry
85 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
86 %arrayidx = getelementptr inbounds i32, ptr %x, i64 %indvars.iv
87 %tmp = load i32, ptr %arrayidx, align 4
88 %arrayidx2 = getelementptr inbounds i32, ptr %y, i64 %indvars.iv
89 %tmp1 = load i32, ptr %arrayidx2, align 4
90 %add = add nsw i32 %tmp1, %tmp
91 %arrayidx4 = getelementptr inbounds i32, ptr %q, i64 %indvars.iv
92 store i32 %add, ptr %arrayidx4, align 4
93 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
94 %exitcond = icmp eq i64 %indvars.iv.next, 1024
95 br i1 %exitcond, label %for.cond.cleanup, label %for.body