mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-13 23:18:51 +00:00
c52d6d530c
This is a cleaned up patch from the one written by John Regehr based on the findings of the Souper superoptimizer. The basic idea here is that input bits that are known zero reduce the maximum count that the intrinsic could return. We know that the number of bits required to represent a particular count is at most log2(N)+1. Differential Revision: http://reviews.llvm.org/D13253 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250338 91177308-0d34-0410-b5e6-96231b3b80d8
46 lines
1.1 KiB
LLVM
46 lines
1.1 KiB
LLVM
; RUN: opt < %s -S -instcombine | FileCheck %s
|
|
|
|
declare i32 @llvm.ctpop.i32(i32)
|
|
declare i8 @llvm.ctpop.i8(i8)
|
|
declare void @llvm.assume(i1)
|
|
|
|
define i1 @test1(i32 %arg) {
|
|
; CHECK: @test1
|
|
; CHECK: ret i1 false
|
|
%and = and i32 %arg, 15
|
|
%cnt = call i32 @llvm.ctpop.i32(i32 %and)
|
|
%res = icmp eq i32 %cnt, 9
|
|
ret i1 %res
|
|
}
|
|
|
|
define i1 @test2(i32 %arg) {
|
|
; CHECK: @test2
|
|
; CHECK: ret i1 false
|
|
%and = and i32 %arg, 1
|
|
%cnt = call i32 @llvm.ctpop.i32(i32 %and)
|
|
%res = icmp eq i32 %cnt, 2
|
|
ret i1 %res
|
|
}
|
|
|
|
define i1 @test3(i32 %arg) {
|
|
; CHECK: @test3
|
|
; CHECK: ret i1 false
|
|
;; Use an assume to make all the bits known without triggering constant
|
|
;; folding. This is trying to hit a corner case where we have to avoid
|
|
;; taking the log of 0.
|
|
%assume = icmp eq i32 %arg, 0
|
|
call void @llvm.assume(i1 %assume)
|
|
%cnt = call i32 @llvm.ctpop.i32(i32 %arg)
|
|
%res = icmp eq i32 %cnt, 2
|
|
ret i1 %res
|
|
}
|
|
|
|
; Negative test for when we know nothing
|
|
define i1 @test4(i8 %arg) {
|
|
; CHECK: @test4
|
|
; CHECK: ret i1 %res
|
|
%cnt = call i8 @llvm.ctpop.i8(i8 %arg)
|
|
%res = icmp eq i8 %cnt, 2
|
|
ret i1 %res
|
|
}
|