This patch precommits tests for: https://github.com/llvm/llvm-project/issues/60802 https://github.com/llvm/llvm-project/issues/61183 which are about std::bit_ceil and std::bit_floor, respectively.
44 lines
1.6 KiB
LLVM
44 lines
1.6 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
|
|
|
|
define i32 @bit_ceil_32(i32 %x) {
|
|
; CHECK-LABEL: @bit_ceil_32(
|
|
; CHECK-NEXT: [[DEC:%.*]] = add i32 [[X:%.*]], -1
|
|
; CHECK-NEXT: [[CTLZ:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[DEC]], i1 false), !range [[RNG0:![0-9]+]]
|
|
; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i32 32, [[CTLZ]]
|
|
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[SUB]]
|
|
; CHECK-NEXT: [[UGT:%.*]] = icmp ugt i32 [[X]], 1
|
|
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[UGT]], i32 [[SHL]], i32 1
|
|
; CHECK-NEXT: ret i32 [[SEL]]
|
|
;
|
|
%dec = add i32 %x, -1
|
|
%ctlz = tail call i32 @llvm.ctlz.i32(i32 %dec, i1 false)
|
|
%sub = sub i32 32, %ctlz
|
|
%shl = shl i32 1, %sub
|
|
%ugt = icmp ugt i32 %x, 1
|
|
%sel = select i1 %ugt, i32 %shl, i32 1
|
|
ret i32 %sel
|
|
}
|
|
|
|
define i64 @bit_ceil_64(i64 %x) {
|
|
; CHECK-LABEL: @bit_ceil_64(
|
|
; CHECK-NEXT: [[DEC:%.*]] = add i64 [[X:%.*]], -1
|
|
; CHECK-NEXT: [[CTLZ:%.*]] = tail call i64 @llvm.ctlz.i64(i64 [[DEC]], i1 false), !range [[RNG1:![0-9]+]]
|
|
; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i64 64, [[CTLZ]]
|
|
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i64 1, [[SUB]]
|
|
; CHECK-NEXT: [[UGT:%.*]] = icmp ugt i64 [[X]], 1
|
|
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[UGT]], i64 [[SHL]], i64 1
|
|
; CHECK-NEXT: ret i64 [[SEL]]
|
|
;
|
|
%dec = add i64 %x, -1
|
|
%ctlz = tail call i64 @llvm.ctlz.i64(i64 %dec, i1 false)
|
|
%sub = sub i64 64, %ctlz
|
|
%shl = shl i64 1, %sub
|
|
%ugt = icmp ugt i64 %x, 1
|
|
%sel = select i1 %ugt, i64 %shl, i64 1
|
|
ret i64 %sel
|
|
}
|
|
|
|
declare i32 @llvm.ctlz.i32(i32, i1 immarg)
|
|
declare i64 @llvm.ctlz.i64(i64, i1 immarg)
|