xref: /aosp_15_r20/external/llvm/test/CodeGen/X86/trunc-to-bool.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; An integer truncation to i1 should be done with an and instruction to make
2*9880d681SAndroid Build Coastguard Worker; sure only the LSBit survives. Test that this is the case both for a returned
3*9880d681SAndroid Build Coastguard Worker; value and as the operand of a branch.
4*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mtriple=i686-unknown-linux-gnu | FileCheck %s
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Workerdefine zeroext i1 @test1(i32 %X)  nounwind {
7*9880d681SAndroid Build Coastguard Worker    %Y = trunc i32 %X to i1
8*9880d681SAndroid Build Coastguard Worker    ret i1 %Y
9*9880d681SAndroid Build Coastguard Worker}
10*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test1:
11*9880d681SAndroid Build Coastguard Worker; CHECK: andb $1, %al
12*9880d681SAndroid Build Coastguard Worker
13*9880d681SAndroid Build Coastguard Workerdefine i1 @test2(i32 %val, i32 %mask) nounwind {
14*9880d681SAndroid Build Coastguard Workerentry:
15*9880d681SAndroid Build Coastguard Worker    %shifted = ashr i32 %val, %mask
16*9880d681SAndroid Build Coastguard Worker    %anded = and i32 %shifted, 1
17*9880d681SAndroid Build Coastguard Worker    %trunced = trunc i32 %anded to i1
18*9880d681SAndroid Build Coastguard Worker    br i1 %trunced, label %ret_true, label %ret_false
19*9880d681SAndroid Build Coastguard Workerret_true:
20*9880d681SAndroid Build Coastguard Worker    ret i1 true
21*9880d681SAndroid Build Coastguard Workerret_false:
22*9880d681SAndroid Build Coastguard Worker    ret i1 false
23*9880d681SAndroid Build Coastguard Worker}
24*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test2:
25*9880d681SAndroid Build Coastguard Worker; CHECK: btl
26*9880d681SAndroid Build Coastguard Worker
27*9880d681SAndroid Build Coastguard Workerdefine i32 @test3(i8* %ptr) nounwind {
28*9880d681SAndroid Build Coastguard Worker    %val = load i8, i8* %ptr
29*9880d681SAndroid Build Coastguard Worker    %tmp = trunc i8 %val to i1
30*9880d681SAndroid Build Coastguard Worker    br i1 %tmp, label %cond_true, label %cond_false
31*9880d681SAndroid Build Coastguard Workercond_true:
32*9880d681SAndroid Build Coastguard Worker    ret i32 21
33*9880d681SAndroid Build Coastguard Workercond_false:
34*9880d681SAndroid Build Coastguard Worker    ret i32 42
35*9880d681SAndroid Build Coastguard Worker}
36*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test3:
37*9880d681SAndroid Build Coastguard Worker; CHECK: testb $1, (%eax)
38*9880d681SAndroid Build Coastguard Worker
39*9880d681SAndroid Build Coastguard Workerdefine i32 @test4(i8* %ptr) nounwind {
40*9880d681SAndroid Build Coastguard Worker    %tmp = ptrtoint i8* %ptr to i1
41*9880d681SAndroid Build Coastguard Worker    br i1 %tmp, label %cond_true, label %cond_false
42*9880d681SAndroid Build Coastguard Workercond_true:
43*9880d681SAndroid Build Coastguard Worker    ret i32 21
44*9880d681SAndroid Build Coastguard Workercond_false:
45*9880d681SAndroid Build Coastguard Worker    ret i32 42
46*9880d681SAndroid Build Coastguard Worker}
47*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test4:
48*9880d681SAndroid Build Coastguard Worker; CHECK: testb $1, 4(%esp)
49*9880d681SAndroid Build Coastguard Worker
50*9880d681SAndroid Build Coastguard Workerdefine i32 @test5(double %d) nounwind {
51*9880d681SAndroid Build Coastguard Worker    %tmp = fptosi double %d to i1
52*9880d681SAndroid Build Coastguard Worker    br i1 %tmp, label %cond_true, label %cond_false
53*9880d681SAndroid Build Coastguard Workercond_true:
54*9880d681SAndroid Build Coastguard Worker    ret i32 21
55*9880d681SAndroid Build Coastguard Workercond_false:
56*9880d681SAndroid Build Coastguard Worker    ret i32 42
57*9880d681SAndroid Build Coastguard Worker}
58*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test5:
59*9880d681SAndroid Build Coastguard Worker; CHECK: testb $1
60