[llvm] 26b3e09 - [x86] Precommit a test
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 1 23:03:47 PST 2023
Author: Kazu Hirata
Date: 2023-03-01T23:03:39-08:00
New Revision: 26b3e096fb5ecb4ae06da9471ac3b99b8316d005
URL: https://github.com/llvm/llvm-project/commit/26b3e096fb5ecb4ae06da9471ac3b99b8316d005
DIFF: https://github.com/llvm/llvm-project/commit/26b3e096fb5ecb4ae06da9471ac3b99b8316d005.diff
LOG: [x86] Precommit a test
This patch precommits a test for:
https://github.com/llvm/llvm-project/issues/60802
Added:
llvm/test/CodeGen/X86/bit_ceil.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/CodeGen/X86/bit_ceil.ll b/llvm/test/CodeGen/X86/bit_ceil.ll
new file mode 100644
index 000000000000..a617d280ca4f
--- /dev/null
+++ b/llvm/test/CodeGen/X86/bit_ceil.ll
@@ -0,0 +1,48 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+bmi2,+lzcnt | FileCheck %s
+
+; Check the assembly sequence generated for std::bit_ceil.
+
+define i32 @bit_ceil_i32(i32 %x) {
+; CHECK-LABEL: bit_ceil_i32:
+; CHECK: # %bb.0:
+; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
+; CHECK-NEXT: leal -1(%rdi), %eax
+; CHECK-NEXT: lzcntl %eax, %eax
+; CHECK-NEXT: negb %al
+; CHECK-NEXT: movl $1, %ecx
+; CHECK-NEXT: shlxl %eax, %ecx, %eax
+; CHECK-NEXT: cmpl $2, %edi
+; CHECK-NEXT: cmovbl %ecx, %eax
+; CHECK-NEXT: retq
+ %dec = add i32 %x, -1
+ %lz = tail call i32 @llvm.ctlz.i32(i32 %dec, i1 false)
+ %cnt = sub i32 32, %lz
+ %res = shl i32 1, %cnt
+ %ugt = icmp ugt i32 %x, 1
+ %sel = select i1 %ugt, i32 %res, i32 1
+ ret i32 %sel
+}
+
+define i64 @bit_ceil_i64(i64 %x) {
+; CHECK-LABEL: bit_ceil_i64:
+; CHECK: # %bb.0:
+; CHECK-NEXT: leaq -1(%rdi), %rax
+; CHECK-NEXT: lzcntq %rax, %rax
+; CHECK-NEXT: negb %al
+; CHECK-NEXT: movl $1, %ecx
+; CHECK-NEXT: shlxq %rax, %rcx, %rax
+; CHECK-NEXT: cmpq $2, %rdi
+; CHECK-NEXT: cmovbq %rcx, %rax
+; CHECK-NEXT: retq
+ %dec = add i64 %x, -1
+ %lz = tail call i64 @llvm.ctlz.i64(i64 %dec, i1 false)
+ %cnt = sub i64 64, %lz
+ %res = shl i64 1, %cnt
+ %ugt = icmp ugt i64 %x, 1
+ %sel = select i1 %ugt, i64 %res, i64 1
+ ret i64 %sel
+}
+
+declare i32 @llvm.ctlz.i32(i32, i1 immarg)
+declare i64 @llvm.ctlz.i64(i64, i1 immarg)
More information about the llvm-commits
mailing list