xref: /llvm-project/llvm/test/Transforms/AggressiveInstCombine/lower-table-based-cttz-zero-element.ll (revision cdfb99b0699595008c971649b50d008ca3fdad6f)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -passes=aggressive-instcombine -S < %s | FileCheck %s
3
4@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
5
6define i32 @ctz1(i32 %x) {
7; CHECK-LABEL: @ctz1(
8; CHECK-NEXT:  entry:
9; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 true)
10; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq i32 [[X]], 0
11; CHECK-NEXT:    [[TMP2:%.*]] = select i1 [[TMP1]], i32 0, i32 [[TMP0]]
12; CHECK-NEXT:    [[TMP3:%.*]] = trunc i32 [[TMP2]] to i8
13; CHECK-NEXT:    [[CONV:%.*]] = zext i8 [[TMP3]] to i32
14; CHECK-NEXT:    ret i32 [[CONV]]
15;
16entry:
17  %sub = sub i32 0, %x
18  %and = and i32 %sub, %x
19  %mul = mul i32 %and, 125613361
20  %shr = lshr i32 %mul, 27
21  %idxprom = zext i32 %shr to i64
22  %arrayidx = getelementptr inbounds [32 x i8], ptr @ctz1.table, i64 0, i64 %idxprom
23  %0 = load i8, ptr %arrayidx, align 1
24  %conv = zext i8 %0 to i32
25  ret i32 %conv
26}
27