From 16507fe9fd3518dc89bea4c6e7f98893ce89b2d1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 5 Jan 2010 07:23:56 +0000 Subject: optimize cttz and ctlz when we can prove something about the leading/trailing bits. Patch by Alastair Lynn! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92706 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Transforms/InstCombine/intrinsics.ll | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'test/Transforms') diff --git a/test/Transforms/InstCombine/intrinsics.ll b/test/Transforms/InstCombine/intrinsics.ll index 135e777..f899fc0 100644 --- a/test/Transforms/InstCombine/intrinsics.ll +++ b/test/Transforms/InstCombine/intrinsics.ll @@ -5,6 +5,8 @@ declare %overflow.result @llvm.uadd.with.overflow.i8(i8, i8) declare %overflow.result @llvm.umul.with.overflow.i8(i8, i8) declare double @llvm.powi.f64(double, i32) nounwind readonly +declare i32 @llvm.cttz.i32(i32) nounwind readnone +declare i8 @llvm.ctlz.i8(i8) nounwind readnone define i8 @test1(i8 %A, i8 %B) { %x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 %A, i8 %B) @@ -79,7 +81,6 @@ define i8 @test6(i8 %A, i1* %overflowPtr) { ; CHECK-NEXT: ret i8 %A } - define void @powi(double %V, double *%P) { entry: %A = tail call double @llvm.powi.f64(double %V, i32 -1) nounwind @@ -98,4 +99,26 @@ entry: ; CHECK: volatile store double %V } +define i32 @cttz(i32 %a) +{ +entry: + %or = or i32 %a, 8 + %and = and i32 %or, -8 + %count = tail call i32 @llvm.cttz.i32(i32 %and) nounwind readnone + ret i32 %count +; CHECK: @cttz +; CHECK-NEXT: entry: +; CHECK-NEXT: ret i32 3 +} +define i8 @ctlz(i8 %a) +{ +entry: + %or = or i8 %a, 32 + %and = and i8 %or, 63 + %count = tail call i8 @llvm.ctlz.i8(i8 %and) nounwind readnone + ret i8 %count +; CHECK: @ctlz +; CHECK-NEXT: entry: +; CHECK-NEXT: ret i8 2 +} -- cgit v1.1