From 92b196b1b60f25ae1bcd068f6a0e8d4e23aba127 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Thu, 15 Jun 2017 15:13:19 +0000 Subject: [PATCH] [InstCombine] auto-generate complete checks; NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305474 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Transforms/InstCombine/ffs-1.ll | 156 ++++++++++++++++++--------- 1 file changed, 106 insertions(+), 50 deletions(-) diff --git a/test/Transforms/InstCombine/ffs-1.ll b/test/Transforms/InstCombine/ffs-1.ll index d27fb5d89f0..af4ee85216e 100644 --- a/test/Transforms/InstCombine/ffs-1.ll +++ b/test/Transforms/InstCombine/ffs-1.ll @@ -1,12 +1,12 @@ ; Test that the ffs* library call simplifier works correctly. ; -; RUN: opt < %s -instcombine -S | FileCheck %s -; RUN: opt < %s -mtriple i386-pc-linux -instcombine -S | FileCheck %s -check-prefix=CHECK-FFS -; RUN: opt -instcombine -mtriple=arm64-apple-ios9.0 -S %s | FileCheck --check-prefix=CHECK-FFS %s -; RUN: opt -instcombine -mtriple=arm64-apple-tvos9.0 -S %s | FileCheck --check-prefix=CHECK-FFS %s -; RUN: opt -instcombine -mtriple=thumbv7k-apple-watchos2.0 -S %s | FileCheck --check-prefix=CHECK-FFS %s -; RUN: opt -instcombine -mtriple=x86_64-apple-macosx10.11 -S %s | FileCheck --check-prefix=CHECK-FFS %s -; RUN: opt -instcombine -mtriple=x86_64-freebsd-gnu -S %s | FileCheck --check-prefix=CHECK-FFS %s +; RUN: opt < %s -instcombine -S | FileCheck %s --check-prefix=ALL --check-prefix=GENERIC +; RUN: opt < %s -instcombine -mtriple i386-pc-linux -S | FileCheck %s --check-prefix=ALL --check-prefix=TARGET +; RUN: opt < %s -instcombine -mtriple=arm64-apple-ios9.0 -S | FileCheck %s --check-prefix=ALL --check-prefix=TARGET +; RUN: opt < %s -instcombine -mtriple=arm64-apple-tvos9.0 -S | FileCheck %s --check-prefix=ALL --check-prefix=TARGET +; RUN: opt < %s -instcombine -mtriple=thumbv7k-apple-watchos2.0 -S | FileCheck %s --check-prefix=ALL --check-prefix=TARGET +; RUN: opt < %s -instcombine -mtriple=x86_64-apple-macosx10.11 -S | FileCheck %s --check-prefix=ALL --check-prefix=TARGET +; RUN: opt < %s -instcombine -mtriple=x86_64-freebsd-gnu -S | FileCheck %s --check-prefix=ALL --check-prefix=TARGET declare i32 @ffs(i32) declare i32 @ffsl(i32) @@ -15,123 +15,179 @@ declare i32 @ffsll(i64) ; Check ffs(0) -> 0. define i32 @test_simplify1() { -; CHECK-LABEL: @test_simplify1( +; ALL-LABEL: @test_simplify1( +; ALL-NEXT: ret i32 0 +; %ret = call i32 @ffs(i32 0) ret i32 %ret -; CHECK-NEXT: ret i32 0 } define i32 @test_simplify2() { -; CHECK-FFS-LABEL: @test_simplify2( +; GENERIC-LABEL: @test_simplify2( +; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsl(i32 0) +; GENERIC-NEXT: ret i32 [[RET]] +; +; TARGET-LABEL: @test_simplify2( +; TARGET-NEXT: ret i32 0 +; %ret = call i32 @ffsl(i32 0) ret i32 %ret -; CHECK-FFS-NEXT: ret i32 0 } define i32 @test_simplify3() { -; CHECK-FFS-LABEL: @test_simplify3( +; GENERIC-LABEL: @test_simplify3( +; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsll(i64 0) +; GENERIC-NEXT: ret i32 [[RET]] +; +; TARGET-LABEL: @test_simplify3( +; TARGET-NEXT: ret i32 0 +; %ret = call i32 @ffsll(i64 0) ret i32 %ret -; CHECK-FFS-NEXT: ret i32 0 } ; Check ffs(c) -> cttz(c) + 1, where 'c' is a constant. define i32 @test_simplify4() { -; CHECK-LABEL: @test_simplify4( +; ALL-LABEL: @test_simplify4( +; ALL-NEXT: ret i32 1 +; %ret = call i32 @ffs(i32 1) ret i32 %ret -; CHECK-NEXT: ret i32 1 } define i32 @test_simplify5() { -; CHECK-LABEL: @test_simplify5( +; ALL-LABEL: @test_simplify5( +; ALL-NEXT: ret i32 12 +; %ret = call i32 @ffs(i32 2048) ret i32 %ret -; CHECK-NEXT: ret i32 12 } define i32 @test_simplify6() { -; CHECK-LABEL: @test_simplify6( +; ALL-LABEL: @test_simplify6( +; ALL-NEXT: ret i32 17 +; %ret = call i32 @ffs(i32 65536) ret i32 %ret -; CHECK-NEXT: ret i32 17 } define i32 @test_simplify7() { -; CHECK-FFS-LABEL: @test_simplify7( +; GENERIC-LABEL: @test_simplify7( +; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsl(i32 65536) +; GENERIC-NEXT: ret i32 [[RET]] +; +; TARGET-LABEL: @test_simplify7( +; TARGET-NEXT: ret i32 17 +; %ret = call i32 @ffsl(i32 65536) ret i32 %ret -; CHECK-FFS-NEXT: ret i32 17 } define i32 @test_simplify8() { -; CHECK-FFS-LABEL: @test_simplify8( +; GENERIC-LABEL: @test_simplify8( +; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsll(i64 1024) +; GENERIC-NEXT: ret i32 [[RET]] +; +; TARGET-LABEL: @test_simplify8( +; TARGET-NEXT: ret i32 11 +; %ret = call i32 @ffsll(i64 1024) ret i32 %ret -; CHECK-FFS-NEXT: ret i32 11 } define i32 @test_simplify9() { -; CHECK-FFS-LABEL: @test_simplify9( +; GENERIC-LABEL: @test_simplify9( +; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsll(i64 65536) +; GENERIC-NEXT: ret i32 [[RET]] +; +; TARGET-LABEL: @test_simplify9( +; TARGET-NEXT: ret i32 17 +; %ret = call i32 @ffsll(i64 65536) ret i32 %ret -; CHECK-FFS-NEXT: ret i32 17 } define i32 @test_simplify10() { -; CHECK-FFS-LABEL: @test_simplify10( +; GENERIC-LABEL: @test_simplify10( +; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsll(i64 17179869184) +; GENERIC-NEXT: ret i32 [[RET]] +; +; TARGET-LABEL: @test_simplify10( +; TARGET-NEXT: ret i32 35 +; %ret = call i32 @ffsll(i64 17179869184) ret i32 %ret -; CHECK-FFS-NEXT: ret i32 35 } define i32 @test_simplify11() { -; CHECK-FFS-LABEL: @test_simplify11( +; GENERIC-LABEL: @test_simplify11( +; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsll(i64 281474976710656) +; GENERIC-NEXT: ret i32 [[RET]] +; +; TARGET-LABEL: @test_simplify11( +; TARGET-NEXT: ret i32 49 +; %ret = call i32 @ffsll(i64 281474976710656) ret i32 %ret -; CHECK-FFS-NEXT: ret i32 49 } define i32 @test_simplify12() { -; CHECK-FFS-LABEL: @test_simplify12( +; GENERIC-LABEL: @test_simplify12( +; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsll(i64 1152921504606846976) +; GENERIC-NEXT: ret i32 [[RET]] +; +; TARGET-LABEL: @test_simplify12( +; TARGET-NEXT: ret i32 61 +; %ret = call i32 @ffsll(i64 1152921504606846976) ret i32 %ret -; CHECK-FFS-NEXT: ret i32 61 } ; Check ffs(x) -> x != 0 ? (i32)llvm.cttz(x) + 1 : 0. define i32 @test_simplify13(i32 %x) { -; CHECK-LABEL: @test_simplify13( +; ALL-LABEL: @test_simplify13( +; ALL-NEXT: [[CTTZ:%.*]] = call i32 @llvm.cttz.i32(i32 %x, i1 true) +; ALL-NEXT: [[TMP1:%.*]] = add nuw nsw i32 [[CTTZ]], 1 +; ALL-NEXT: [[TMP2:%.*]] = icmp ne i32 %x, 0 +; ALL-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], i32 [[TMP1]], i32 0 +; ALL-NEXT: ret i32 [[TMP3]] +; %ret = call i32 @ffs(i32 %x) -; CHECK-NEXT: [[CTTZ:%[a-z0-9]+]] = call i32 @llvm.cttz.i32(i32 %x, i1 true) -; CHECK-NEXT: [[INC:%[a-z0-9]+]] = add nuw nsw i32 [[CTTZ]], 1 -; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 %x, 0 -; CHECK-NEXT: [[RET:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[INC]], i32 0 ret i32 %ret -; CHECK-NEXT: ret i32 [[RET]] } define i32 @test_simplify14(i32 %x) { -; CHECK-FFS-LABEL: @test_simplify14( +; GENERIC-LABEL: @test_simplify14( +; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsl(i32 %x) +; GENERIC-NEXT: ret i32 [[RET]] +; +; TARGET-LABEL: @test_simplify14( +; TARGET-NEXT: [[CTTZ:%.*]] = call i32 @llvm.cttz.i32(i32 %x, i1 true) +; TARGET-NEXT: [[TMP1:%.*]] = add nuw nsw i32 [[CTTZ]], 1 +; TARGET-NEXT: [[TMP2:%.*]] = icmp ne i32 %x, 0 +; TARGET-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], i32 [[TMP1]], i32 0 +; TARGET-NEXT: ret i32 [[TMP3]] +; %ret = call i32 @ffsl(i32 %x) -; CHECK-FFS-NEXT: [[CTTZ:%[a-z0-9]+]] = call i32 @llvm.cttz.i32(i32 %x, i1 true) -; CHECK-FFS-NEXT: [[INC:%[a-z0-9]+]] = add nuw nsw i32 [[CTTZ]], 1 -; CHECK-FFS-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 %x, 0 -; CHECK-FFS-NEXT: [[RET:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[INC]], i32 0 ret i32 %ret -; CHECK-FFS-NEXT: ret i32 [[RET]] } define i32 @test_simplify15(i64 %x) { -; CHECK-FFS-LABEL: @test_simplify15( +; GENERIC-LABEL: @test_simplify15( +; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsll(i64 %x) +; GENERIC-NEXT: ret i32 [[RET]] +; +; TARGET-LABEL: @test_simplify15( +; TARGET-NEXT: [[CTTZ:%.*]] = call i64 @llvm.cttz.i64(i64 %x, i1 true) +; TARGET-NEXT: [[TMP1:%.*]] = add nuw nsw i64 [[CTTZ]], 1 +; TARGET-NEXT: [[TMP2:%.*]] = trunc i64 [[TMP1]] to i32 +; TARGET-NEXT: [[TMP3:%.*]] = icmp ne i64 %x, 0 +; TARGET-NEXT: [[TMP4:%.*]] = select i1 [[TMP3]], i32 [[TMP2]], i32 0 +; TARGET-NEXT: ret i32 [[TMP4]] +; %ret = call i32 @ffsll(i64 %x) -; CHECK-FFS-NEXT: [[CTTZ:%[a-z0-9]+]] = call i64 @llvm.cttz.i64(i64 %x, i1 true) -; CHECK-FFS-NEXT: [[INC:%[a-z0-9]+]] = add nuw nsw i64 [[CTTZ]], 1 -; CHECK-FFS-NEXT: [[TRUNC:%[a-z0-9]+]] = trunc i64 [[INC]] to i32 -; CHECK-FFS-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i64 %x, 0 -; CHECK-FFS-NEXT: [[RET:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[TRUNC]], i32 0 ret i32 %ret -; CHECK-FFS-NEXT: ret i32 [[RET]] } + -- 2.50.1