[llvm] [InstCombine] Lower ilogb to bit operations for normal values (PR #218044)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 24 06:06:24 PDT 2026
================
@@ -199,5 +199,253 @@ define i32 @ilogb_poison() {
ret i32 %r
}
-declare i32 @ilogbf(float)
+
+; The following tests are for the ilogb normal optimization where floating-point
+; numbers which are known to be normal can have the exponent extracted using
+; simple bit manipulations.
+
+; copysign is used to create a fp value which won't cause the ilogb call to
+; be immediately constant-folded.
+
+define i32 @ilogb_known_normal_non_pow2(double %sign) {
+; CHECK-LABEL: define i32 @ilogb_known_normal_non_pow2(double %sign) {
+; CHECK-NEXT: ret i32 3
+;
+ %x = call double @llvm.copysign.f64(double 12.5, double %sign)
+ %r = call i32 @ilogb(double %x)
+ ret i32 %r
+}
+
+define i32 @ilogbf_known_normal_non_pow2(float %sign) {
+; CHECK-LABEL: define i32 @ilogbf_known_normal_non_pow2(float %sign) {
+; CHECK-NEXT: ret i32 3
+;
+ %x = call float @llvm.copysign.f32(float 12.5, float %sign)
+ %r = call i32 @ilogbf(float %x)
----------------
tadeuszjt wrote:
I'm not sure how errno would be tested in this case because ilogb appears to only set errno for non-normal cases.
https://github.com/llvm/llvm-project/pull/218044
More information about the llvm-commits
mailing list