1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
3 ; Test that the fls library call simplifier works correctly even for
4 ; targets with 16-bit int. Although fls is available on a number of
5 ; targets it's supported (hardcoded as available) only on FreeBSD.
7 ; RUN: opt < %s -mtriple=avr-freebsd -passes=instcombine -S | FileCheck %s --check-prefix=AVR
8 ; RUN: opt < %s -mtriple=msp430-freebsd -passes=instcombine -S | FileCheck %s --check-prefix=MSP430
9 ; REQUIRES: avr-registered-target,msp430-registered-target
13 declare void @sink(i16)
16 define void @fold_fls(i16 %x) {
17 ; AVR-LABEL: @fold_fls(
18 ; AVR-NEXT: call addrspace(1) void @sink(i16 0)
19 ; AVR-NEXT: call addrspace(1) void @sink(i16 1)
20 ; AVR-NEXT: [[CTLZ:%.*]] = call addrspace(1) i16 @llvm.ctlz.i16(i16 [[X:%.*]], i1 false), !range [[RNG0:![0-9]+]]
21 ; AVR-NEXT: [[NX:%.*]] = sub nuw nsw i16 16, [[CTLZ]]
22 ; AVR-NEXT: call addrspace(1) void @sink(i16 [[NX]])
25 ; MSP430-LABEL: @fold_fls(
26 ; MSP430-NEXT: call void @sink(i16 0)
27 ; MSP430-NEXT: call void @sink(i16 1)
28 ; MSP430-NEXT: [[CTLZ:%.*]] = call i16 @llvm.ctlz.i16(i16 [[X:%.*]], i1 false), !range [[RNG0:![0-9]+]]
29 ; MSP430-NEXT: [[NX:%.*]] = sub nuw nsw i16 16, [[CTLZ]]
30 ; MSP430-NEXT: call void @sink(i16 [[NX]])
31 ; MSP430-NEXT: ret void
33 %n0 = call i16 @fls(i16 0)
34 call void @sink(i16 %n0)
36 %n1 = call i16 @fls(i16 1)
37 call void @sink(i16 %n1)
39 %nx = call i16 @fls(i16 %x)
40 call void @sink(i16 %nx)