From: Alexey Bataev Date: Mon, 3 Oct 2016 07:47:01 +0000 (+0000) Subject: [CodeGen] Adding a test showing the current state of poor code gen of X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6fd795dee81e6b2f3e08fcdfd58ce1cc840acfd8;p=llvm [CodeGen] Adding a test showing the current state of poor code gen of search loop, by Andrey Tischenko PR27136 shows failure to hoist constant out of loop. This test is used as start point to fix the failure: it shows the current state of codegen and discovers what should be fixed Differential Revision: https://reviews.llvm.org/D25097 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283091 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/CodeGen/X86/loop-search.ll b/test/CodeGen/X86/loop-search.ll new file mode 100644 index 00000000000..99c21ae8dd4 --- /dev/null +++ b/test/CodeGen/X86/loop-search.ll @@ -0,0 +1,67 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s + +; This test comes from PR27136 +; We should hoist loop constant invariant + +define zeroext i1 @search(i32 %needle, i32* nocapture readonly %haystack, i32 %count) { +; CHECK-LABEL: search: +; CHECK: ## BB#0: ## %entry +; CHECK-NEXT: testl %edx, %edx +; CHECK-NEXT: jle LBB0_1 +; CHECK-NEXT: ## BB#4: ## %for.body.preheader +; CHECK-NEXT: movslq %edx, %rcx +; CHECK-NEXT: xorl %edx, %edx +; CHECK-NEXT: .p2align 4, 0x90 +; CHECK-NEXT: LBB0_5: ## %for.body +; CHECK-NEXT: ## =>This Inner Loop Header: Depth=1 +; ### FIXME: This loop invariant should be hoisted +; CHECK-NEXT: movb $1, %al +; CHECK-NEXT: cmpl %edi, (%rsi,%rdx,4) +; CHECK-NEXT: je LBB0_6 +; CHECK-NEXT: ## BB#2: ## %for.cond +; CHECK-NEXT: ## in Loop: Header=BB0_5 Depth=1 +; CHECK-NEXT: incq %rdx +; CHECK-NEXT: cmpq %rcx, %rdx +; CHECK-NEXT: jl LBB0_5 +; ### FIXME: BB#3 and LBB0_1 should be merged +; CHECK-NEXT: ## BB#3: +; CHECK-NEXT: xorl %eax, %eax +; CHECK-NEXT: ## kill: %AL %AL %EAX +; CHECK-NEXT: retq +; CHECK-NEXT: LBB0_1: +; CHECK-NEXT: xorl %eax, %eax +; CHECK-NEXT: ## kill: %AL %AL %EAX +; CHECK-NEXT: retq +; CHECK-NEXT: LBB0_6: ## %cleanup +; CHECK-NEXT: ## kill: %AL %AL %EAX +; CHECK-NEXT: retq +; +entry: + %cmp5 = icmp sgt i32 %count, 0 + br i1 %cmp5, label %for.body.preheader, label %cleanup + +for.body.preheader: ; preds = %entry + %0 = sext i32 %count to i64 + br label %for.body + +for.cond: ; preds = %for.body + %cmp = icmp slt i64 %indvars.iv.next, %0 + br i1 %cmp, label %for.body, label %cleanup.loopexit + +for.body: ; preds = %for.body.preheader, %for.cond + %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.cond ] + %arrayidx = getelementptr inbounds i32, i32* %haystack, i64 %indvars.iv + %1 = load i32, i32* %arrayidx, align 4 + %cmp1 = icmp eq i32 %1, %needle + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 + br i1 %cmp1, label %cleanup.loopexit, label %for.cond + +cleanup.loopexit: ; preds = %for.cond, %for.body + %.ph = phi i1 [ false, %for.cond ], [ true, %for.body ] + br label %cleanup + +cleanup: ; preds = %cleanup.loopexit, %entry + %2 = phi i1 [ false, %entry ], [ %.ph, %cleanup.loopexit ] + ret i1 %2 +}