1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s
4 ; This test comes from PR27136
5 ; We should hoist loop constant invariant
7 define zeroext i1 @search(i32 %needle, i32* nocapture readonly %haystack, i32 %count) {
9 ; CHECK: ## %bb.0: ## %entry
10 ; CHECK-NEXT: testl %edx, %edx
11 ; CHECK-NEXT: jle LBB0_5
12 ; CHECK-NEXT: ## %bb.1: ## %for.body.preheader
13 ; CHECK-NEXT: movslq %edx, %rax
14 ; CHECK-NEXT: xorl %ecx, %ecx
15 ; CHECK-NEXT: .p2align 4, 0x90
16 ; CHECK-NEXT: LBB0_2: ## %for.body
17 ; CHECK-NEXT: ## =>This Inner Loop Header: Depth=1
18 ; CHECK-NEXT: cmpl %edi, (%rsi,%rcx,4)
19 ; CHECK-NEXT: je LBB0_6
20 ; CHECK-NEXT: ## %bb.3: ## %for.cond
21 ; CHECK-NEXT: ## in Loop: Header=BB0_2 Depth=1
22 ; CHECK-NEXT: incq %rcx
23 ; CHECK-NEXT: cmpq %rax, %rcx
24 ; CHECK-NEXT: jl LBB0_2
26 ; CHECK-NEXT: xorl %eax, %eax
27 ; CHECK-NEXT: ## kill: def $al killed $al killed $eax
30 ; CHECK-NEXT: movb $1, %al
31 ; CHECK-NEXT: ## kill: def $al killed $al killed $eax
34 %cmp5 = icmp sgt i32 %count, 0
35 br i1 %cmp5, label %for.body.preheader, label %cleanup
37 for.body.preheader: ; preds = %entry
38 %0 = sext i32 %count to i64
41 for.cond: ; preds = %for.body
42 %cmp = icmp slt i64 %indvars.iv.next, %0
43 br i1 %cmp, label %for.body, label %cleanup.loopexit
45 for.body: ; preds = %for.body.preheader, %for.cond
46 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.cond ]
47 %arrayidx = getelementptr inbounds i32, i32* %haystack, i64 %indvars.iv
48 %1 = load i32, i32* %arrayidx, align 4
49 %cmp1 = icmp eq i32 %1, %needle
50 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
51 br i1 %cmp1, label %cleanup.loopexit, label %for.cond
53 cleanup.loopexit: ; preds = %for.cond, %for.body
54 %.ph = phi i1 [ false, %for.cond ], [ true, %for.body ]
57 cleanup: ; preds = %cleanup.loopexit, %entry
58 %2 = phi i1 [ false, %entry ], [ %.ph, %cleanup.loopexit ]