Ensure MDNode used as key in metadata linking map cannot be RAUWed
[oota-llvm.git] / test / Transforms / InstCombine / ctpop.ll
1 ; RUN: opt < %s -S -instcombine | FileCheck %s
2
3 declare i32 @llvm.ctpop.i32(i32)
4 declare i8 @llvm.ctpop.i8(i8)
5 declare void @llvm.assume(i1)
6
7 define i1 @test1(i32 %arg) {
8 ; CHECK: @test1
9 ; CHECK: ret i1 false
10   %and = and i32 %arg, 15
11   %cnt = call i32 @llvm.ctpop.i32(i32 %and)
12   %res = icmp eq i32 %cnt, 9
13   ret i1 %res
14 }
15
16 define i1 @test2(i32 %arg) {
17 ; CHECK: @test2
18 ; CHECK: ret i1 false
19   %and = and i32 %arg, 1
20   %cnt = call i32 @llvm.ctpop.i32(i32 %and)
21   %res = icmp eq i32 %cnt, 2
22   ret i1 %res
23 }
24
25 define i1 @test3(i32 %arg) {
26 ; CHECK: @test3
27 ; CHECK: ret i1 false
28   ;; Use an assume to make all the bits known without triggering constant 
29   ;; folding.  This is trying to hit a corner case where we have to avoid
30   ;; taking the log of 0.
31   %assume = icmp eq i32 %arg, 0
32   call void @llvm.assume(i1 %assume)
33   %cnt = call i32 @llvm.ctpop.i32(i32 %arg)
34   %res = icmp eq i32 %cnt, 2
35   ret i1 %res
36 }
37
38 ; Negative test for when we know nothing
39 define i1 @test4(i8 %arg) {
40 ; CHECK: @test4
41 ; CHECK: ret i1 %res
42   %cnt = call i8 @llvm.ctpop.i8(i8 %arg)
43   %res = icmp eq i8 %cnt, 2
44   ret i1 %res
45 }