[llvm] [InstCombine] Lower ilogb to bit operations for normal values (PR #218044)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 24 00:07:39 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)
----------------
arsenm wrote:
ilogb can set errno, and this seems to be missing the check
https://github.com/llvm/llvm-project/pull/218044
More information about the llvm-commits
mailing list