[llvm] 6e9e538 - [LoopIdiomRecognize] Autogenerate complete checks for the X86 ctlz/cttz tests. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 11 15:36:55 PST 2020
Author: Craig Topper
Date: 2020-12-11T15:35:37-08:00
New Revision: 6e9e53895cf72b93c0a1f97afdd7780db1fc133e
URL: https://github.com/llvm/llvm-project/commit/6e9e53895cf72b93c0a1f97afdd7780db1fc133e
DIFF: https://github.com/llvm/llvm-project/commit/6e9e53895cf72b93c0a1f97afdd7780db1fc133e.diff
LOG: [LoopIdiomRecognize] Autogenerate complete checks for the X86 ctlz/cttz tests. NFC
Preparation for D92745 which will add more tests to these files.
Added:
Modified:
llvm/test/Transforms/LoopIdiom/X86/ctlz.ll
llvm/test/Transforms/LoopIdiom/X86/cttz.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/LoopIdiom/X86/ctlz.ll b/llvm/test/Transforms/LoopIdiom/X86/ctlz.ll
index 12f1043475ce..117946cf3d2c 100644
--- a/llvm/test/Transforms/LoopIdiom/X86/ctlz.ll
+++ b/llvm/test/Transforms/LoopIdiom/X86/ctlz.ll
@@ -1,5 +1,6 @@
-; RUN: opt -loop-idiom -mtriple=x86_64 -mcpu=core-avx2 < %s -S | FileCheck -check-prefix=LZCNT --check-prefix=ALL %s
-; RUN: opt -loop-idiom -mtriple=x86_64 -mcpu=corei7 < %s -S | FileCheck -check-prefix=NOLZCNT --check-prefix=ALL %s
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -loop-idiom -mtriple=x86_64 -mcpu=core-avx2 < %s -S | FileCheck %s -check-prefixes=ALL,LZCNT
+; RUN: opt -loop-idiom -mtriple=x86_64 -mcpu=corei7 < %s -S | FileCheck %s -check-prefixes=ALL,NOLZCNT
; Recognize CTLZ builtin pattern.
; Here we'll just convert loop to countable,
@@ -16,20 +17,76 @@
; return i;
; }
;
-; LZCNT: entry
-; LZCNT: %0 = call i32 @llvm.ctlz.i32(i32 %shr8, i1 true)
-; LZCNT-NEXT: %1 = sub i32 32, %0
-; LZCNT-NEXT: %2 = zext i32 %1 to i64
-; LZCNT: %indvars.iv.next.lcssa = phi i64 [ %2, %while.body ]
-; LZCNT: %4 = trunc i64 %indvars.iv.next.lcssa to i32
-; LZCNT: %i.0.lcssa = phi i32 [ 0, %entry ], [ %4, %while.end.loopexit ]
-; LZCNT: ret i32 %i.0.lcssa
-
-; NOLZCNT: entry
-; NOLZCNT-NOT: @llvm.ctlz
-
-; Function Attrs: norecurse nounwind uwtable
define i32 @ctlz_and_other(i32 %n, i8* nocapture %a) {
+; LZCNT-LABEL: @ctlz_and_other(
+; LZCNT-NEXT: entry:
+; LZCNT-NEXT: [[C:%.*]] = icmp sgt i32 [[N:%.*]], 0
+; LZCNT-NEXT: [[NEGN:%.*]] = sub nsw i32 0, [[N]]
+; LZCNT-NEXT: [[ABS_N:%.*]] = select i1 [[C]], i32 [[N]], i32 [[NEGN]]
+; LZCNT-NEXT: [[SHR8:%.*]] = lshr i32 [[ABS_N]], 1
+; LZCNT-NEXT: [[TOBOOL9:%.*]] = icmp eq i32 [[SHR8]], 0
+; LZCNT-NEXT: br i1 [[TOBOOL9]], label [[WHILE_END:%.*]], label [[WHILE_BODY_PREHEADER:%.*]]
+; LZCNT: while.body.preheader:
+; LZCNT-NEXT: [[TMP0:%.*]] = call i32 @llvm.ctlz.i32(i32 [[SHR8]], i1 true)
+; LZCNT-NEXT: [[TMP1:%.*]] = sub i32 32, [[TMP0]]
+; LZCNT-NEXT: [[TMP2:%.*]] = zext i32 [[TMP1]] to i64
+; LZCNT-NEXT: br label [[WHILE_BODY:%.*]]
+; LZCNT: while.body:
+; LZCNT-NEXT: [[TCPHI:%.*]] = phi i32 [ [[TMP1]], [[WHILE_BODY_PREHEADER]] ], [ [[TCDEC:%.*]], [[WHILE_BODY]] ]
+; LZCNT-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[WHILE_BODY]] ], [ 0, [[WHILE_BODY_PREHEADER]] ]
+; LZCNT-NEXT: [[SHR11:%.*]] = phi i32 [ [[SHR:%.*]], [[WHILE_BODY]] ], [ [[SHR8]], [[WHILE_BODY_PREHEADER]] ]
+; LZCNT-NEXT: [[TMP3:%.*]] = trunc i64 [[INDVARS_IV]] to i32
+; LZCNT-NEXT: [[SHL:%.*]] = shl i32 1, [[TMP3]]
+; LZCNT-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[ABS_N]]
+; LZCNT-NEXT: [[TOBOOL1:%.*]] = icmp ne i32 [[AND]], 0
+; LZCNT-NEXT: [[CONV:%.*]] = zext i1 [[TOBOOL1]] to i8
+; LZCNT-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8, i8* [[A:%.*]], i64 [[INDVARS_IV]]
+; LZCNT-NEXT: store i8 [[CONV]], i8* [[ARRAYIDX]], align 1
+; LZCNT-NEXT: [[INDVARS_IV_NEXT]] = add nuw i64 [[INDVARS_IV]], 1
+; LZCNT-NEXT: [[SHR]] = ashr i32 [[SHR11]], 1
+; LZCNT-NEXT: [[TCDEC]] = sub nsw i32 [[TCPHI]], 1
+; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[TCDEC]], 0
+; LZCNT-NEXT: br i1 [[TOBOOL]], label [[WHILE_END_LOOPEXIT:%.*]], label [[WHILE_BODY]]
+; LZCNT: while.end.loopexit:
+; LZCNT-NEXT: [[INDVARS_IV_NEXT_LCSSA:%.*]] = phi i64 [ [[TMP2]], [[WHILE_BODY]] ]
+; LZCNT-NEXT: [[TMP4:%.*]] = trunc i64 [[INDVARS_IV_NEXT_LCSSA]] to i32
+; LZCNT-NEXT: br label [[WHILE_END]]
+; LZCNT: while.end:
+; LZCNT-NEXT: [[I_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[TMP4]], [[WHILE_END_LOOPEXIT]] ]
+; LZCNT-NEXT: ret i32 [[I_0_LCSSA]]
+;
+; NOLZCNT-LABEL: @ctlz_and_other(
+; NOLZCNT-NEXT: entry:
+; NOLZCNT-NEXT: [[C:%.*]] = icmp sgt i32 [[N:%.*]], 0
+; NOLZCNT-NEXT: [[NEGN:%.*]] = sub nsw i32 0, [[N]]
+; NOLZCNT-NEXT: [[ABS_N:%.*]] = select i1 [[C]], i32 [[N]], i32 [[NEGN]]
+; NOLZCNT-NEXT: [[SHR8:%.*]] = lshr i32 [[ABS_N]], 1
+; NOLZCNT-NEXT: [[TOBOOL9:%.*]] = icmp eq i32 [[SHR8]], 0
+; NOLZCNT-NEXT: br i1 [[TOBOOL9]], label [[WHILE_END:%.*]], label [[WHILE_BODY_PREHEADER:%.*]]
+; NOLZCNT: while.body.preheader:
+; NOLZCNT-NEXT: br label [[WHILE_BODY:%.*]]
+; NOLZCNT: while.body:
+; NOLZCNT-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[WHILE_BODY]] ], [ 0, [[WHILE_BODY_PREHEADER]] ]
+; NOLZCNT-NEXT: [[SHR11:%.*]] = phi i32 [ [[SHR:%.*]], [[WHILE_BODY]] ], [ [[SHR8]], [[WHILE_BODY_PREHEADER]] ]
+; NOLZCNT-NEXT: [[TMP0:%.*]] = trunc i64 [[INDVARS_IV]] to i32
+; NOLZCNT-NEXT: [[SHL:%.*]] = shl i32 1, [[TMP0]]
+; NOLZCNT-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[ABS_N]]
+; NOLZCNT-NEXT: [[TOBOOL1:%.*]] = icmp ne i32 [[AND]], 0
+; NOLZCNT-NEXT: [[CONV:%.*]] = zext i1 [[TOBOOL1]] to i8
+; NOLZCNT-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8, i8* [[A:%.*]], i64 [[INDVARS_IV]]
+; NOLZCNT-NEXT: store i8 [[CONV]], i8* [[ARRAYIDX]], align 1
+; NOLZCNT-NEXT: [[INDVARS_IV_NEXT]] = add nuw i64 [[INDVARS_IV]], 1
+; NOLZCNT-NEXT: [[SHR]] = ashr i32 [[SHR11]], 1
+; NOLZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[SHR]], 0
+; NOLZCNT-NEXT: br i1 [[TOBOOL]], label [[WHILE_END_LOOPEXIT:%.*]], label [[WHILE_BODY]]
+; NOLZCNT: while.end.loopexit:
+; NOLZCNT-NEXT: [[INDVARS_IV_NEXT_LCSSA:%.*]] = phi i64 [ [[INDVARS_IV_NEXT]], [[WHILE_BODY]] ]
+; NOLZCNT-NEXT: [[TMP1:%.*]] = trunc i64 [[INDVARS_IV_NEXT_LCSSA]] to i32
+; NOLZCNT-NEXT: br label [[WHILE_END]]
+; NOLZCNT: while.end:
+; NOLZCNT-NEXT: [[I_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[TMP1]], [[WHILE_END_LOOPEXIT]] ]
+; NOLZCNT-NEXT: ret i32 [[I_0_LCSSA]]
+;
entry:
%c = icmp sgt i32 %n, 0
%negn = sub nsw i32 0, %n
@@ -80,15 +137,34 @@ while.end: ; preds = %while.end.loopexit,
; return i;
; }
;
-; ALL: entry
-; ALL: %0 = call i32 @llvm.ctlz.i32(i32 %abs_n, i1 true)
-; ALL-NEXT: %1 = sub i32 32, %0
-; ALL: %inc.lcssa = phi i32 [ %1, %while.body ]
-; ALL: %i.0.lcssa = phi i32 [ 0, %entry ], [ %inc.lcssa, %while.end.loopexit ]
-; ALL: ret i32 %i.0.lcssa
-
-; Function Attrs: norecurse nounwind readnone uwtable
define i32 @ctlz_zero_check(i32 %n) {
+; ALL-LABEL: @ctlz_zero_check(
+; ALL-NEXT: entry:
+; ALL-NEXT: [[C:%.*]] = icmp sgt i32 [[N:%.*]], 0
+; ALL-NEXT: [[NEGN:%.*]] = sub nsw i32 0, [[N]]
+; ALL-NEXT: [[ABS_N:%.*]] = select i1 [[C]], i32 [[N]], i32 [[NEGN]]
+; ALL-NEXT: [[TOBOOL4:%.*]] = icmp eq i32 [[ABS_N]], 0
+; ALL-NEXT: br i1 [[TOBOOL4]], label [[WHILE_END:%.*]], label [[WHILE_BODY_PREHEADER:%.*]]
+; ALL: while.body.preheader:
+; ALL-NEXT: [[TMP0:%.*]] = call i32 @llvm.ctlz.i32(i32 [[ABS_N]], i1 true)
+; ALL-NEXT: [[TMP1:%.*]] = sub i32 32, [[TMP0]]
+; ALL-NEXT: br label [[WHILE_BODY:%.*]]
+; ALL: while.body:
+; ALL-NEXT: [[TCPHI:%.*]] = phi i32 [ [[TMP1]], [[WHILE_BODY_PREHEADER]] ], [ [[TCDEC:%.*]], [[WHILE_BODY]] ]
+; ALL-NEXT: [[I_06:%.*]] = phi i32 [ [[INC:%.*]], [[WHILE_BODY]] ], [ 0, [[WHILE_BODY_PREHEADER]] ]
+; ALL-NEXT: [[N_ADDR_05:%.*]] = phi i32 [ [[SHR:%.*]], [[WHILE_BODY]] ], [ [[ABS_N]], [[WHILE_BODY_PREHEADER]] ]
+; ALL-NEXT: [[SHR]] = ashr i32 [[N_ADDR_05]], 1
+; ALL-NEXT: [[INC]] = add nsw i32 [[I_06]], 1
+; ALL-NEXT: [[TCDEC]] = sub nsw i32 [[TCPHI]], 1
+; ALL-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[TCDEC]], 0
+; ALL-NEXT: br i1 [[TOBOOL]], label [[WHILE_END_LOOPEXIT:%.*]], label [[WHILE_BODY]]
+; ALL: while.end.loopexit:
+; ALL-NEXT: [[INC_LCSSA:%.*]] = phi i32 [ [[TMP1]], [[WHILE_BODY]] ]
+; ALL-NEXT: br label [[WHILE_END]]
+; ALL: while.end:
+; ALL-NEXT: [[I_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC_LCSSA]], [[WHILE_END_LOOPEXIT]] ]
+; ALL-NEXT: ret i32 [[I_0_LCSSA]]
+;
entry:
%c = icmp sgt i32 %n, 0
%negn = sub nsw i32 0, %n
@@ -129,15 +205,31 @@ while.end: ; preds = %while.end.loopexit,
; return i;
; }
;
-; ALL: entry
-; ALL: %0 = call i32 @llvm.ctlz.i32(i32 %n, i1 true)
-; ALL-NEXT: %1 = sub i32 32, %0
-; ALL: %inc.lcssa = phi i32 [ %1, %while.body ]
-; ALL: %i.0.lcssa = phi i32 [ 0, %entry ], [ %inc.lcssa, %while.end.loopexit ]
-; ALL: ret i32 %i.0.lcssa
-
-; Function Attrs: norecurse nounwind readnone uwtable
define i32 @ctlz_zero_check_lshr(i32 %n) {
+; ALL-LABEL: @ctlz_zero_check_lshr(
+; ALL-NEXT: entry:
+; ALL-NEXT: [[TOBOOL4:%.*]] = icmp eq i32 [[N:%.*]], 0
+; ALL-NEXT: br i1 [[TOBOOL4]], label [[WHILE_END:%.*]], label [[WHILE_BODY_PREHEADER:%.*]]
+; ALL: while.body.preheader:
+; ALL-NEXT: [[TMP0:%.*]] = call i32 @llvm.ctlz.i32(i32 [[N]], i1 true)
+; ALL-NEXT: [[TMP1:%.*]] = sub i32 32, [[TMP0]]
+; ALL-NEXT: br label [[WHILE_BODY:%.*]]
+; ALL: while.body:
+; ALL-NEXT: [[TCPHI:%.*]] = phi i32 [ [[TMP1]], [[WHILE_BODY_PREHEADER]] ], [ [[TCDEC:%.*]], [[WHILE_BODY]] ]
+; ALL-NEXT: [[I_06:%.*]] = phi i32 [ [[INC:%.*]], [[WHILE_BODY]] ], [ 0, [[WHILE_BODY_PREHEADER]] ]
+; ALL-NEXT: [[N_ADDR_05:%.*]] = phi i32 [ [[SHR:%.*]], [[WHILE_BODY]] ], [ [[N]], [[WHILE_BODY_PREHEADER]] ]
+; ALL-NEXT: [[SHR]] = lshr i32 [[N_ADDR_05]], 1
+; ALL-NEXT: [[INC]] = add nsw i32 [[I_06]], 1
+; ALL-NEXT: [[TCDEC]] = sub nsw i32 [[TCPHI]], 1
+; ALL-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[TCDEC]], 0
+; ALL-NEXT: br i1 [[TOBOOL]], label [[WHILE_END_LOOPEXIT:%.*]], label [[WHILE_BODY]]
+; ALL: while.end.loopexit:
+; ALL-NEXT: [[INC_LCSSA:%.*]] = phi i32 [ [[TMP1]], [[WHILE_BODY]] ]
+; ALL-NEXT: br label [[WHILE_END]]
+; ALL: while.end:
+; ALL-NEXT: [[I_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC_LCSSA]], [[WHILE_END_LOOPEXIT]] ]
+; ALL-NEXT: ret i32 [[I_0_LCSSA]]
+;
entry:
%tobool4 = icmp eq i32 %n, 0
br i1 %tobool4, label %while.end, label %while.body.preheader
@@ -175,16 +267,30 @@ while.end: ; preds = %while.end.loopexit,
; return i;
; }
;
-; ALL: entry
-; ALL: %0 = ashr i32 %abs_n, 1
-; ALL-NEXT: %1 = call i32 @llvm.ctlz.i32(i32 %0, i1 false)
-; ALL-NEXT: %2 = sub i32 32, %1
-; ALL-NEXT: %3 = add i32 %2, 1
-; ALL: %i.0.lcssa = phi i32 [ %2, %while.cond ]
-; ALL: ret i32 %i.0.lcssa
-
-; Function Attrs: norecurse nounwind readnone uwtable
define i32 @ctlz(i32 %n) {
+; ALL-LABEL: @ctlz(
+; ALL-NEXT: entry:
+; ALL-NEXT: [[C:%.*]] = icmp sgt i32 [[N:%.*]], 0
+; ALL-NEXT: [[NEGN:%.*]] = sub nsw i32 0, [[N]]
+; ALL-NEXT: [[ABS_N:%.*]] = select i1 [[C]], i32 [[N]], i32 [[NEGN]]
+; ALL-NEXT: [[TMP0:%.*]] = ashr i32 [[ABS_N]], 1
+; ALL-NEXT: [[TMP1:%.*]] = call i32 @llvm.ctlz.i32(i32 [[TMP0]], i1 false)
+; ALL-NEXT: [[TMP2:%.*]] = sub i32 32, [[TMP1]]
+; ALL-NEXT: [[TMP3:%.*]] = add i32 [[TMP2]], 1
+; ALL-NEXT: br label [[WHILE_COND:%.*]]
+; ALL: while.cond:
+; ALL-NEXT: [[TCPHI:%.*]] = phi i32 [ [[TMP3]], [[ENTRY:%.*]] ], [ [[TCDEC:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[N_ADDR_0:%.*]] = phi i32 [ [[ABS_N]], [[ENTRY]] ], [ [[SHR:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[INC:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[SHR]] = ashr i32 [[N_ADDR_0]], 1
+; ALL-NEXT: [[TCDEC]] = sub nsw i32 [[TCPHI]], 1
+; ALL-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[TCDEC]], 0
+; ALL-NEXT: [[INC]] = add nsw i32 [[I_0]], 1
+; ALL-NEXT: br i1 [[TOBOOL]], label [[WHILE_END:%.*]], label [[WHILE_COND]]
+; ALL: while.end:
+; ALL-NEXT: [[I_0_LCSSA:%.*]] = phi i32 [ [[TMP2]], [[WHILE_COND]] ]
+; ALL-NEXT: ret i32 [[I_0_LCSSA]]
+;
entry:
%c = icmp sgt i32 %n, 0
%negn = sub nsw i32 0, %n
@@ -216,16 +322,27 @@ while.end: ; preds = %while.cond
; return i;
; }
;
-; ALL: entry
-; ALL: %0 = lshr i32 %n, 1
-; ALL-NEXT: %1 = call i32 @llvm.ctlz.i32(i32 %0, i1 false)
-; ALL-NEXT: %2 = sub i32 32, %1
-; ALL-NEXT: %3 = add i32 %2, 1
-; ALL: %i.0.lcssa = phi i32 [ %2, %while.cond ]
-; ALL: ret i32 %i.0.lcssa
-
-; Function Attrs: norecurse nounwind readnone uwtable
define i32 @ctlz_lshr(i32 %n) {
+; ALL-LABEL: @ctlz_lshr(
+; ALL-NEXT: entry:
+; ALL-NEXT: [[TMP0:%.*]] = lshr i32 [[N:%.*]], 1
+; ALL-NEXT: [[TMP1:%.*]] = call i32 @llvm.ctlz.i32(i32 [[TMP0]], i1 false)
+; ALL-NEXT: [[TMP2:%.*]] = sub i32 32, [[TMP1]]
+; ALL-NEXT: [[TMP3:%.*]] = add i32 [[TMP2]], 1
+; ALL-NEXT: br label [[WHILE_COND:%.*]]
+; ALL: while.cond:
+; ALL-NEXT: [[TCPHI:%.*]] = phi i32 [ [[TMP3]], [[ENTRY:%.*]] ], [ [[TCDEC:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[N_ADDR_0:%.*]] = phi i32 [ [[N]], [[ENTRY]] ], [ [[SHR:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[INC:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[SHR]] = lshr i32 [[N_ADDR_0]], 1
+; ALL-NEXT: [[TCDEC]] = sub nsw i32 [[TCPHI]], 1
+; ALL-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[TCDEC]], 0
+; ALL-NEXT: [[INC]] = add nsw i32 [[I_0]], 1
+; ALL-NEXT: br i1 [[TOBOOL]], label [[WHILE_END:%.*]], label [[WHILE_COND]]
+; ALL: while.end:
+; ALL-NEXT: [[I_0_LCSSA:%.*]] = phi i32 [ [[TMP2]], [[WHILE_COND]] ]
+; ALL-NEXT: ret i32 [[I_0_LCSSA]]
+;
entry:
br label %while.cond
@@ -255,17 +372,31 @@ while.end: ; preds = %while.cond
; return i;
; }
;
-; ALL: entry
-; ALL: %0 = ashr i32 %abs_n, 1
-; ALL-NEXT: %1 = call i32 @llvm.ctlz.i32(i32 %0, i1 false)
-; ALL-NEXT: %2 = sub i32 32, %1
-; ALL-NEXT: %3 = add i32 %2, 1
-; ALL-NEXT: %4 = add i32 %2, %i0
-; ALL: %i.0.lcssa = phi i32 [ %4, %while.cond ]
-; ALL: ret i32 %i.0.lcssa
-;
-; Function Attrs: norecurse nounwind readnone uwtable
define i32 @ctlz_add(i32 %n, i32 %i0) {
+; ALL-LABEL: @ctlz_add(
+; ALL-NEXT: entry:
+; ALL-NEXT: [[C:%.*]] = icmp sgt i32 [[N:%.*]], 0
+; ALL-NEXT: [[NEGN:%.*]] = sub nsw i32 0, [[N]]
+; ALL-NEXT: [[ABS_N:%.*]] = select i1 [[C]], i32 [[N]], i32 [[NEGN]]
+; ALL-NEXT: [[TMP0:%.*]] = ashr i32 [[ABS_N]], 1
+; ALL-NEXT: [[TMP1:%.*]] = call i32 @llvm.ctlz.i32(i32 [[TMP0]], i1 false)
+; ALL-NEXT: [[TMP2:%.*]] = sub i32 32, [[TMP1]]
+; ALL-NEXT: [[TMP3:%.*]] = add i32 [[TMP2]], 1
+; ALL-NEXT: [[TMP4:%.*]] = add i32 [[TMP2]], [[I0:%.*]]
+; ALL-NEXT: br label [[WHILE_COND:%.*]]
+; ALL: while.cond:
+; ALL-NEXT: [[TCPHI:%.*]] = phi i32 [ [[TMP3]], [[ENTRY:%.*]] ], [ [[TCDEC:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[N_ADDR_0:%.*]] = phi i32 [ [[ABS_N]], [[ENTRY]] ], [ [[SHR:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[I_0:%.*]] = phi i32 [ [[I0]], [[ENTRY]] ], [ [[INC:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[SHR]] = ashr i32 [[N_ADDR_0]], 1
+; ALL-NEXT: [[TCDEC]] = sub nsw i32 [[TCPHI]], 1
+; ALL-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[TCDEC]], 0
+; ALL-NEXT: [[INC]] = add nsw i32 [[I_0]], 1
+; ALL-NEXT: br i1 [[TOBOOL]], label [[WHILE_END:%.*]], label [[WHILE_COND]]
+; ALL: while.end:
+; ALL-NEXT: [[I_0_LCSSA:%.*]] = phi i32 [ [[TMP4]], [[WHILE_COND]] ]
+; ALL-NEXT: ret i32 [[I_0_LCSSA]]
+;
entry:
%c = icmp sgt i32 %n, 0
%negn = sub nsw i32 0, %n
@@ -297,17 +428,28 @@ while.end: ; preds = %while.cond
; return i;
; }
;
-; ALL: entry
-; ALL: %0 = lshr i32 %n, 1
-; ALL-NEXT: %1 = call i32 @llvm.ctlz.i32(i32 %0, i1 false)
-; ALL-NEXT: %2 = sub i32 32, %1
-; ALL-NEXT: %3 = add i32 %2, 1
-; ALL-NEXT: %4 = add i32 %2, %i0
-; ALL: %i.0.lcssa = phi i32 [ %4, %while.cond ]
-; ALL: ret i32 %i.0.lcssa
-;
-; Function Attrs: norecurse nounwind readnone uwtable
define i32 @ctlz_add_lshr(i32 %n, i32 %i0) {
+; ALL-LABEL: @ctlz_add_lshr(
+; ALL-NEXT: entry:
+; ALL-NEXT: [[TMP0:%.*]] = lshr i32 [[N:%.*]], 1
+; ALL-NEXT: [[TMP1:%.*]] = call i32 @llvm.ctlz.i32(i32 [[TMP0]], i1 false)
+; ALL-NEXT: [[TMP2:%.*]] = sub i32 32, [[TMP1]]
+; ALL-NEXT: [[TMP3:%.*]] = add i32 [[TMP2]], 1
+; ALL-NEXT: [[TMP4:%.*]] = add i32 [[TMP2]], [[I0:%.*]]
+; ALL-NEXT: br label [[WHILE_COND:%.*]]
+; ALL: while.cond:
+; ALL-NEXT: [[TCPHI:%.*]] = phi i32 [ [[TMP3]], [[ENTRY:%.*]] ], [ [[TCDEC:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[N_ADDR_0:%.*]] = phi i32 [ [[N]], [[ENTRY]] ], [ [[SHR:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[I_0:%.*]] = phi i32 [ [[I0]], [[ENTRY]] ], [ [[INC:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[SHR]] = lshr i32 [[N_ADDR_0]], 1
+; ALL-NEXT: [[TCDEC]] = sub nsw i32 [[TCPHI]], 1
+; ALL-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[TCDEC]], 0
+; ALL-NEXT: [[INC]] = add nsw i32 [[I_0]], 1
+; ALL-NEXT: br i1 [[TOBOOL]], label [[WHILE_END:%.*]], label [[WHILE_COND]]
+; ALL: while.end:
+; ALL-NEXT: [[I_0_LCSSA:%.*]] = phi i32 [ [[TMP4]], [[WHILE_COND]] ]
+; ALL-NEXT: ret i32 [[I_0_LCSSA]]
+;
entry:
br label %while.cond
@@ -339,16 +481,31 @@ while.end: ; preds = %while.cond
; return i;
; }
;
-; ALL: entry
-; ALL: %0 = ashr i32 %abs_n, 1
-; ALL-NEXT: %1 = call i32 @llvm.ctlz.i32(i32 %0, i1 false)
-; ALL-NEXT: %2 = sub i32 32, %1
-; ALL-NEXT: %3 = add i32 %2, 1
-; ALL: %i.0.lcssa = phi i32 [ %2, %while.cond ]
-; ALL: ret i32 %i.0.lcssa
-
-; Function Attrs: norecurse nounwind readnone uwtable
define i32 @ctlz_sext(i16 %in) {
+; ALL-LABEL: @ctlz_sext(
+; ALL-NEXT: entry:
+; ALL-NEXT: [[N:%.*]] = sext i16 [[IN:%.*]] to i32
+; ALL-NEXT: [[C:%.*]] = icmp sgt i16 [[IN]], 0
+; ALL-NEXT: [[NEGN:%.*]] = sub nsw i32 0, [[N]]
+; ALL-NEXT: [[ABS_N:%.*]] = select i1 [[C]], i32 [[N]], i32 [[NEGN]]
+; ALL-NEXT: [[TMP0:%.*]] = ashr i32 [[ABS_N]], 1
+; ALL-NEXT: [[TMP1:%.*]] = call i32 @llvm.ctlz.i32(i32 [[TMP0]], i1 false)
+; ALL-NEXT: [[TMP2:%.*]] = sub i32 32, [[TMP1]]
+; ALL-NEXT: [[TMP3:%.*]] = add i32 [[TMP2]], 1
+; ALL-NEXT: br label [[WHILE_COND:%.*]]
+; ALL: while.cond:
+; ALL-NEXT: [[TCPHI:%.*]] = phi i32 [ [[TMP3]], [[ENTRY:%.*]] ], [ [[TCDEC:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[N_ADDR_0:%.*]] = phi i32 [ [[ABS_N]], [[ENTRY]] ], [ [[SHR:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[INC:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[SHR]] = ashr i32 [[N_ADDR_0]], 1
+; ALL-NEXT: [[TCDEC]] = sub nsw i32 [[TCPHI]], 1
+; ALL-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[TCDEC]], 0
+; ALL-NEXT: [[INC]] = add nsw i32 [[I_0]], 1
+; ALL-NEXT: br i1 [[TOBOOL]], label [[WHILE_END:%.*]], label [[WHILE_COND]]
+; ALL: while.end:
+; ALL-NEXT: [[I_0_LCSSA:%.*]] = phi i32 [ [[TMP2]], [[WHILE_COND]] ]
+; ALL-NEXT: ret i32 [[I_0_LCSSA]]
+;
entry:
%n = sext i16 %in to i32
%c = icmp sgt i16 %in, 0
@@ -381,16 +538,28 @@ while.end: ; preds = %while.cond
; return i;
; }
;
-; ALL: entry
-; ALL: %0 = lshr i32 %n, 1
-; ALL-NEXT: %1 = call i32 @llvm.ctlz.i32(i32 %0, i1 false)
-; ALL-NEXT: %2 = sub i32 32, %1
-; ALL-NEXT: %3 = add i32 %2, 1
-; ALL: %i.0.lcssa = phi i32 [ %2, %while.cond ]
-; ALL: ret i32 %i.0.lcssa
-
-; Function Attrs: norecurse nounwind readnone uwtable
define i32 @ctlz_sext_lshr(i16 %in) {
+; ALL-LABEL: @ctlz_sext_lshr(
+; ALL-NEXT: entry:
+; ALL-NEXT: [[N:%.*]] = sext i16 [[IN:%.*]] to i32
+; ALL-NEXT: [[TMP0:%.*]] = lshr i32 [[N]], 1
+; ALL-NEXT: [[TMP1:%.*]] = call i32 @llvm.ctlz.i32(i32 [[TMP0]], i1 false)
+; ALL-NEXT: [[TMP2:%.*]] = sub i32 32, [[TMP1]]
+; ALL-NEXT: [[TMP3:%.*]] = add i32 [[TMP2]], 1
+; ALL-NEXT: br label [[WHILE_COND:%.*]]
+; ALL: while.cond:
+; ALL-NEXT: [[TCPHI:%.*]] = phi i32 [ [[TMP3]], [[ENTRY:%.*]] ], [ [[TCDEC:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[N_ADDR_0:%.*]] = phi i32 [ [[N]], [[ENTRY]] ], [ [[SHR:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[INC:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[SHR]] = lshr i32 [[N_ADDR_0]], 1
+; ALL-NEXT: [[TCDEC]] = sub nsw i32 [[TCPHI]], 1
+; ALL-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[TCDEC]], 0
+; ALL-NEXT: [[INC]] = add nsw i32 [[I_0]], 1
+; ALL-NEXT: br i1 [[TOBOOL]], label [[WHILE_END:%.*]], label [[WHILE_COND]]
+; ALL: while.end:
+; ALL-NEXT: [[I_0_LCSSA:%.*]] = phi i32 [ [[TMP2]], [[WHILE_COND]] ]
+; ALL-NEXT: ret i32 [[I_0_LCSSA]]
+;
entry:
%n = sext i16 %in to i32
br label %while.cond
@@ -413,49 +582,27 @@ while.end: ; preds = %while.cond
; we convert this to a countable loop using ctlz that loop will only run 32
; times. This is
diff erent than the infinite number of times of the original.
define i32 @foo(i32 %x) {
-; LZCNT-LABEL: @foo(
-; LZCNT-NEXT: entry:
-; LZCNT-NEXT: [[V:%.*]] = alloca i8, align 1
-; LZCNT-NEXT: [[TOBOOL4:%.*]] = icmp eq i32 [[X:%.*]], 0
-; LZCNT-NEXT: br i1 [[TOBOOL4]], label [[WHILE_END:%.*]], label [[WHILE_BODY_LR_PH:%.*]]
-; LZCNT: while.body.lr.ph:
-; LZCNT-NEXT: br label [[WHILE_BODY:%.*]]
-; LZCNT: while.body:
-; LZCNT-NEXT: [[CNT_06:%.*]] = phi i32 [ 0, [[WHILE_BODY_LR_PH]] ], [ [[INC:%.*]], [[WHILE_BODY]] ]
-; LZCNT-NEXT: [[X_ADDR_05:%.*]] = phi i32 [ [[X]], [[WHILE_BODY_LR_PH]] ], [ [[SHR:%.*]], [[WHILE_BODY]] ]
-; LZCNT-NEXT: [[SHR]] = ashr i32 [[X_ADDR_05]], 1
-; LZCNT-NEXT: [[INC]] = add i32 [[CNT_06]], 1
-; LZCNT-NEXT: store volatile i8 42, i8* [[V]], align 1
-; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[SHR]], 0
-; LZCNT-NEXT: br i1 [[TOBOOL]], label [[WHILE_COND_WHILE_END_CRIT_EDGE:%.*]], label [[WHILE_BODY]]
-; LZCNT: while.cond.while.end_crit_edge:
-; LZCNT-NEXT: [[SPLIT:%.*]] = phi i32 [ [[INC]], [[WHILE_BODY]] ]
-; LZCNT-NEXT: br label [[WHILE_END]]
-; LZCNT: while.end:
-; LZCNT-NEXT: [[CNT_0_LCSSA:%.*]] = phi i32 [ [[SPLIT]], [[WHILE_COND_WHILE_END_CRIT_EDGE]] ], [ 0, [[ENTRY:%.*]] ]
-; LZCNT-NEXT: ret i32 [[CNT_0_LCSSA]]
-;
-; NOLZCNT-LABEL: @foo(
-; NOLZCNT-NEXT: entry:
-; NOLZCNT-NEXT: [[V:%.*]] = alloca i8, align 1
-; NOLZCNT-NEXT: [[TOBOOL4:%.*]] = icmp eq i32 [[X:%.*]], 0
-; NOLZCNT-NEXT: br i1 [[TOBOOL4]], label [[WHILE_END:%.*]], label [[WHILE_BODY_LR_PH:%.*]]
-; NOLZCNT: while.body.lr.ph:
-; NOLZCNT-NEXT: br label [[WHILE_BODY:%.*]]
-; NOLZCNT: while.body:
-; NOLZCNT-NEXT: [[CNT_06:%.*]] = phi i32 [ 0, [[WHILE_BODY_LR_PH]] ], [ [[INC:%.*]], [[WHILE_BODY]] ]
-; NOLZCNT-NEXT: [[X_ADDR_05:%.*]] = phi i32 [ [[X]], [[WHILE_BODY_LR_PH]] ], [ [[SHR:%.*]], [[WHILE_BODY]] ]
-; NOLZCNT-NEXT: [[SHR]] = ashr i32 [[X_ADDR_05]], 1
-; NOLZCNT-NEXT: [[INC]] = add i32 [[CNT_06]], 1
-; NOLZCNT-NEXT: store volatile i8 42, i8* [[V]], align 1
-; NOLZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[SHR]], 0
-; NOLZCNT-NEXT: br i1 [[TOBOOL]], label [[WHILE_COND_WHILE_END_CRIT_EDGE:%.*]], label [[WHILE_BODY]]
-; NOLZCNT: while.cond.while.end_crit_edge:
-; NOLZCNT-NEXT: [[SPLIT:%.*]] = phi i32 [ [[INC]], [[WHILE_BODY]] ]
-; NOLZCNT-NEXT: br label [[WHILE_END]]
-; NOLZCNT: while.end:
-; NOLZCNT-NEXT: [[CNT_0_LCSSA:%.*]] = phi i32 [ [[SPLIT]], [[WHILE_COND_WHILE_END_CRIT_EDGE]] ], [ 0, [[ENTRY:%.*]] ]
-; NOLZCNT-NEXT: ret i32 [[CNT_0_LCSSA]]
+; ALL-LABEL: @foo(
+; ALL-NEXT: entry:
+; ALL-NEXT: [[V:%.*]] = alloca i8, align 1
+; ALL-NEXT: [[TOBOOL4:%.*]] = icmp eq i32 [[X:%.*]], 0
+; ALL-NEXT: br i1 [[TOBOOL4]], label [[WHILE_END:%.*]], label [[WHILE_BODY_LR_PH:%.*]]
+; ALL: while.body.lr.ph:
+; ALL-NEXT: br label [[WHILE_BODY:%.*]]
+; ALL: while.body:
+; ALL-NEXT: [[CNT_06:%.*]] = phi i32 [ 0, [[WHILE_BODY_LR_PH]] ], [ [[INC:%.*]], [[WHILE_BODY]] ]
+; ALL-NEXT: [[X_ADDR_05:%.*]] = phi i32 [ [[X]], [[WHILE_BODY_LR_PH]] ], [ [[SHR:%.*]], [[WHILE_BODY]] ]
+; ALL-NEXT: [[SHR]] = ashr i32 [[X_ADDR_05]], 1
+; ALL-NEXT: [[INC]] = add i32 [[CNT_06]], 1
+; ALL-NEXT: store volatile i8 42, i8* [[V]], align 1
+; ALL-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[SHR]], 0
+; ALL-NEXT: br i1 [[TOBOOL]], label [[WHILE_COND_WHILE_END_CRIT_EDGE:%.*]], label [[WHILE_BODY]]
+; ALL: while.cond.while.end_crit_edge:
+; ALL-NEXT: [[SPLIT:%.*]] = phi i32 [ [[INC]], [[WHILE_BODY]] ]
+; ALL-NEXT: br label [[WHILE_END]]
+; ALL: while.end:
+; ALL-NEXT: [[CNT_0_LCSSA:%.*]] = phi i32 [ [[SPLIT]], [[WHILE_COND_WHILE_END_CRIT_EDGE]] ], [ 0, [[ENTRY:%.*]] ]
+; ALL-NEXT: ret i32 [[CNT_0_LCSSA]]
;
entry:
%v = alloca i8, align 1
@@ -496,7 +643,6 @@ while.end: ; preds = %while.cond.while.en
; return i;
; }
;
-; Function Attrs: norecurse nounwind readnone uwtable
define i32 @ctlz_bad(i32 %n) {
; ALL-LABEL: @ctlz_bad(
; ALL-NEXT: entry:
diff --git a/llvm/test/Transforms/LoopIdiom/X86/cttz.ll b/llvm/test/Transforms/LoopIdiom/X86/cttz.ll
index e18fecabe86e..82bc8207eb0e 100644
--- a/llvm/test/Transforms/LoopIdiom/X86/cttz.ll
+++ b/llvm/test/Transforms/LoopIdiom/X86/cttz.ll
@@ -1,3 +1,4 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -loop-idiom -mtriple=x86_64 -mcpu=core-avx2 < %s -S | FileCheck --check-prefix=ALL %s
; RUN: opt -loop-idiom -mtriple=x86_64 -mcpu=corei7 < %s -S | FileCheck --check-prefix=ALL %s
@@ -15,12 +16,31 @@
; return i;
; }
;
-; ALL-LABEL: @cttz_zero_check
-; ALL: %0 = call i32 @llvm.cttz.i32(i32 %n, i1 true)
-; ALL-NEXT: %1 = sub i32 32, %0
-;
-; Function Attrs: norecurse nounwind readnone uwtable
define i32 @cttz_zero_check(i32 %n) {
+; ALL-LABEL: @cttz_zero_check(
+; ALL-NEXT: entry:
+; ALL-NEXT: [[TOBOOL4:%.*]] = icmp eq i32 [[N:%.*]], 0
+; ALL-NEXT: br i1 [[TOBOOL4]], label [[WHILE_END:%.*]], label [[WHILE_BODY_PREHEADER:%.*]]
+; ALL: while.body.preheader:
+; ALL-NEXT: [[TMP0:%.*]] = call i32 @llvm.cttz.i32(i32 [[N]], i1 true)
+; ALL-NEXT: [[TMP1:%.*]] = sub i32 32, [[TMP0]]
+; ALL-NEXT: br label [[WHILE_BODY:%.*]]
+; ALL: while.body:
+; ALL-NEXT: [[TCPHI:%.*]] = phi i32 [ [[TMP1]], [[WHILE_BODY_PREHEADER]] ], [ [[TCDEC:%.*]], [[WHILE_BODY]] ]
+; ALL-NEXT: [[I_06:%.*]] = phi i32 [ [[INC:%.*]], [[WHILE_BODY]] ], [ 0, [[WHILE_BODY_PREHEADER]] ]
+; ALL-NEXT: [[N_ADDR_05:%.*]] = phi i32 [ [[SHL:%.*]], [[WHILE_BODY]] ], [ [[N]], [[WHILE_BODY_PREHEADER]] ]
+; ALL-NEXT: [[SHL]] = shl i32 [[N_ADDR_05]], 1
+; ALL-NEXT: [[INC]] = add nsw i32 [[I_06]], 1
+; ALL-NEXT: [[TCDEC]] = sub nsw i32 [[TCPHI]], 1
+; ALL-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[TCDEC]], 0
+; ALL-NEXT: br i1 [[TOBOOL]], label [[WHILE_END_LOOPEXIT:%.*]], label [[WHILE_BODY]]
+; ALL: while.end.loopexit:
+; ALL-NEXT: [[INC_LCSSA:%.*]] = phi i32 [ [[TMP1]], [[WHILE_BODY]] ]
+; ALL-NEXT: br label [[WHILE_END]]
+; ALL: while.end:
+; ALL-NEXT: [[I_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC_LCSSA]], [[WHILE_END_LOOPEXIT]] ]
+; ALL-NEXT: ret i32 [[I_0_LCSSA]]
+;
entry:
%tobool4 = icmp eq i32 %n, 0
br i1 %tobool4, label %while.end, label %while.body.preheader
@@ -57,14 +77,27 @@ while.end: ; preds = %while.end.loopexit,
; return i;
; }
;
-; ALL-LABEL: @cttz
-; ALL: %0 = shl i32 %n, 1
-; ALL-NEXT: %1 = call i32 @llvm.cttz.i32(i32 %0, i1 false)
-; ALL-NEXT: %2 = sub i32 32, %1
-; ALL-NEXT: %3 = add i32 %2, 1
-;
-; Function Attrs: norecurse nounwind readnone uwtable
define i32 @cttz(i32 %n) {
+; ALL-LABEL: @cttz(
+; ALL-NEXT: entry:
+; ALL-NEXT: [[TMP0:%.*]] = shl i32 [[N:%.*]], 1
+; ALL-NEXT: [[TMP1:%.*]] = call i32 @llvm.cttz.i32(i32 [[TMP0]], i1 false)
+; ALL-NEXT: [[TMP2:%.*]] = sub i32 32, [[TMP1]]
+; ALL-NEXT: [[TMP3:%.*]] = add i32 [[TMP2]], 1
+; ALL-NEXT: br label [[WHILE_COND:%.*]]
+; ALL: while.cond:
+; ALL-NEXT: [[TCPHI:%.*]] = phi i32 [ [[TMP3]], [[ENTRY:%.*]] ], [ [[TCDEC:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[N_ADDR_0:%.*]] = phi i32 [ [[N]], [[ENTRY]] ], [ [[SHL:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[INC:%.*]], [[WHILE_COND]] ]
+; ALL-NEXT: [[SHL]] = shl i32 [[N_ADDR_0]], 1
+; ALL-NEXT: [[TCDEC]] = sub nsw i32 [[TCPHI]], 1
+; ALL-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[TCDEC]], 0
+; ALL-NEXT: [[INC]] = add nsw i32 [[I_0]], 1
+; ALL-NEXT: br i1 [[TOBOOL]], label [[WHILE_END:%.*]], label [[WHILE_COND]]
+; ALL: while.end:
+; ALL-NEXT: [[I_0_LCSSA:%.*]] = phi i32 [ [[TMP2]], [[WHILE_COND]] ]
+; ALL-NEXT: ret i32 [[I_0_LCSSA]]
+;
entry:
br label %while.cond
More information about the llvm-commits
mailing list