brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 3585fe9 Raw
70 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -O1 -S -mattr=+lzcnt | FileCheck %s3 4target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"5target triple = "x86_64-unknown-linux-gnu"6 7; This test ensures we are able to optimize the following loop to an llvm.abs8; followed by an llvm.ctlz.9; FIXME: LoopIdiom recongize is not forming llvm.ctlz.10 11; int ctlz_zero_check(int n)12; {13;   n = n >= 0 ? n : -n;14;   int i = 0;15;   while(n) {16;     n >>= 1;17;     i++;18;   }19;   return i;20; }21 22define i32 @ctlz_loop_with_abs(i32 %n) {23; CHECK-LABEL: @ctlz_loop_with_abs(24; CHECK-NEXT:  entry:25; CHECK-NEXT:    [[TOBOOL_NOT1:%.*]] = icmp eq i32 [[N:%.*]], 026; CHECK-NEXT:    br i1 [[TOBOOL_NOT1]], label [[WHILE_END:%.*]], label [[WHILE_BODY_PREHEADER:%.*]]27; CHECK:       while.body.preheader:28; CHECK-NEXT:    [[TMP0:%.*]] = tail call i32 @llvm.abs.i32(i32 [[N]], i1 true)29; CHECK-NEXT:    br label [[WHILE_BODY:%.*]]30; CHECK:       while.body:31; CHECK-NEXT:    [[N_ADDR_03:%.*]] = phi i32 [ [[TMP1:%.*]], [[WHILE_BODY]] ], [ [[TMP0]], [[WHILE_BODY_PREHEADER]] ]32; CHECK-NEXT:    [[I_02:%.*]] = phi i32 [ [[INC:%.*]], [[WHILE_BODY]] ], [ 0, [[WHILE_BODY_PREHEADER]] ]33; CHECK-NEXT:    [[TMP1]] = lshr i32 [[N_ADDR_03]], 134; CHECK-NEXT:    [[INC]] = add nuw nsw i32 [[I_02]], 135; CHECK-NEXT:    [[TOBOOL_NOT:%.*]] = icmp eq i32 [[TMP1]], 036; CHECK-NEXT:    br i1 [[TOBOOL_NOT]], label [[WHILE_END]], label [[WHILE_BODY]]37; CHECK:       while.end:38; CHECK-NEXT:    [[I_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC]], [[WHILE_BODY]] ]39; CHECK-NEXT:    ret i32 [[I_0_LCSSA]]40;41entry:42  %cmp = icmp sge i32 %n, 043  br i1 %cmp, label %cond.true, label %cond.false44 45cond.true:                                        ; preds = %entry46  br label %cond.end47 48cond.false:                                       ; preds = %entry49  %sub = sub nsw i32 0, %n50  br label %cond.end51 52cond.end:                                         ; preds = %cond.false, %cond.true53  %cond = phi i32 [ %n, %cond.true ], [ %sub, %cond.false ]54  br label %while.cond55 56while.cond:                                       ; preds = %while.body, %cond.end57  %i.0 = phi i32 [ 0, %cond.end ], [ %inc, %while.body ]58  %n.addr.0 = phi i32 [ %cond, %cond.end ], [ %shr, %while.body ]59  %tobool = icmp ne i32 %n.addr.0, 060  br i1 %tobool, label %while.body, label %while.end61 62while.body:                                       ; preds = %while.cond63  %shr = ashr i32 %n.addr.0, 164  %inc = add nsw i32 %i.0, 165  br label %while.cond66 67while.end:                                        ; preds = %while.cond68  ret i32 %i.069}70