27 lines
1.0 KiB
LLVM
27 lines
1.0 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt -passes=aggressive-instcombine -S < %s | FileCheck %s
|
|
|
|
@ctz1.table = internal constant [32 x i8] c"\00\01\1C\02\1D\0E\18\03\1E\16\14\0F\19\11\04\08\1F\1B\0D\17\15\13\10\07\1A\0C\12\06\0B\05\0A\09", align 1
|
|
|
|
define i32 @ctz1(i32 %x) {
|
|
; CHECK-LABEL: @ctz1(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 true)
|
|
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[X]], 0
|
|
; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 0, i32 [[TMP0]]
|
|
; CHECK-NEXT: [[TMP3:%.*]] = trunc i32 [[TMP2]] to i8
|
|
; CHECK-NEXT: [[CONV:%.*]] = zext i8 [[TMP3]] to i32
|
|
; CHECK-NEXT: ret i32 [[CONV]]
|
|
;
|
|
entry:
|
|
%sub = sub i32 0, %x
|
|
%and = and i32 %sub, %x
|
|
%mul = mul i32 %and, 125613361
|
|
%shr = lshr i32 %mul, 27
|
|
%idxprom = zext i32 %shr to i64
|
|
%arrayidx = getelementptr inbounds [32 x i8], [32 x i8]* @ctz1.table, i64 0, i64 %idxprom
|
|
%0 = load i8, i8* %arrayidx, align 1
|
|
%conv = zext i8 %0 to i32
|
|
ret i32 %conv
|
|
}
|