Evgeny Stupachenko | c675290 | 2017-08-07 19:56:34 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -loop-reduce -mtriple=x86_64 -S | FileCheck %s -check-prefix=BOTH -check-prefix=INSN |
| 2 | ; RUN: opt < %s -loop-reduce -mtriple=x86_64 -lsr-insns-cost=false -S | FileCheck %s -check-prefix=BOTH -check-prefix=REGS |
Evgeny Stupachenko | fe6f548 | 2017-02-11 02:57:43 +0000 | [diff] [blame] | 3 | ; RUN: llc < %s -O2 -march=x86-64 -lsr-insns-cost -asm-verbose=0 | FileCheck %s |
| 4 | |
| 5 | ; OPT checks that LSR prefers less instructions to less registers. |
| 6 | ; For x86 LSR should prefer complicated address to new lsr induction |
| 7 | ; variables. |
| 8 | |
| 9 | ; BOTH: for.body: |
| 10 | ; INSN: getelementptr i32, i32* %x, i64 %indvars.iv |
| 11 | ; INSN: getelementptr i32, i32* %y, i64 %indvars.iv |
| 12 | ; INSN: getelementptr i32, i32* %q, i64 %indvars.iv |
| 13 | ; REGS %lsr.iv4 = phi |
| 14 | ; REGS %lsr.iv2 = phi |
| 15 | ; REGS %lsr.iv1 = phi |
| 16 | ; REGS: getelementptr i32, i32* %lsr.iv1, i64 1 |
| 17 | ; REGS: getelementptr i32, i32* %lsr.iv2, i64 1 |
| 18 | ; REGS: getelementptr i32, i32* %lsr.iv4, i64 1 |
| 19 | |
| 20 | ; LLC checks that LSR prefers less instructions to less registers. |
| 21 | ; LSR should prefer complicated address to additonal add instructions. |
| 22 | |
| 23 | ; CHECK: LBB0_2: |
Evgeny Stupachenko | 5f3d9b6 | 2017-02-11 05:39:00 +0000 | [diff] [blame] | 24 | ; CHECK-NEXT: movl (%r{{.+}}, |
| 25 | ; CHECK-NEXT: addl (%r{{.+}}, |
| 26 | ; CHECK-NEXT: movl %e{{.+}}, (%r{{.+}}, |
Evgeny Stupachenko | fe6f548 | 2017-02-11 02:57:43 +0000 | [diff] [blame] | 27 | |
| 28 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 29 | |
| 30 | ; Function Attrs: norecurse nounwind uwtable |
| 31 | define void @foo(i32* nocapture readonly %x, i32* nocapture readonly %y, i32* nocapture %q, i32 %n) { |
| 32 | entry: |
| 33 | %cmp10 = icmp sgt i32 %n, 0 |
| 34 | br i1 %cmp10, label %for.body.preheader, label %for.cond.cleanup |
| 35 | |
| 36 | for.body.preheader: ; preds = %entry |
| 37 | %wide.trip.count = zext i32 %n to i64 |
| 38 | br label %for.body |
| 39 | |
| 40 | for.cond.cleanup.loopexit: ; preds = %for.body |
| 41 | br label %for.cond.cleanup |
| 42 | |
| 43 | for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry |
| 44 | ret void |
| 45 | |
| 46 | for.body: ; preds = %for.body, %for.body.preheader |
| 47 | %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ] |
| 48 | %arrayidx = getelementptr inbounds i32, i32* %x, i64 %indvars.iv |
| 49 | %tmp = load i32, i32* %arrayidx, align 4 |
| 50 | %arrayidx2 = getelementptr inbounds i32, i32* %y, i64 %indvars.iv |
| 51 | %tmp1 = load i32, i32* %arrayidx2, align 4 |
| 52 | %add = add nsw i32 %tmp1, %tmp |
| 53 | %arrayidx4 = getelementptr inbounds i32, i32* %q, i64 %indvars.iv |
| 54 | store i32 %add, i32* %arrayidx4, align 4 |
| 55 | %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 |
| 56 | %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count |
| 57 | br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body |
| 58 | } |