[llvm] [InstCombine] fold `ldexp(x, zext(i1 y))` to `fmul x, (select y, 2.0, 1.0)` (PR #94887)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 9 10:14:48 PDT 2024
================
@@ -0,0 +1,57 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+define float @ldexp_zext_float(float %x, i1 %bool) {
+; CHECK-LABEL: @ldexp_zext_float(
+; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[BOOL:%.*]], float 2.000000e+00, float 1.000000e+00
+; CHECK-NEXT: [[LDEXP:%.*]] = fmul float [[TMP1]], [[X:%.*]]
+; CHECK-NEXT: ret float [[LDEXP]]
+;
+ %zext = zext i1 %bool to i32
+ %ldexp = call float @llvm.ldexp.f32.i32(float %x, i32 %zext)
+ ret float %ldexp
+}
+
+define float @ldexp_zext_float_negative(float %x, i8 %y) {
+; CHECK-LABEL: @ldexp_zext_float_negative(
+; CHECK-NEXT: [[ZEXT:%.*]] = zext i8 [[Y:%.*]] to i32
+; CHECK-NEXT: [[LDEXP:%.*]] = call float @llvm.ldexp.f32.i32(float [[X:%.*]], i32 [[ZEXT]])
+; CHECK-NEXT: ret float [[LDEXP]]
+;
+ %zext = zext i8 %y to i32
+ %ldexp = call float @llvm.ldexp.f32.i32(float %x, i32 %zext)
+ ret float %ldexp
+}
+
+define double @ldexp_zext_double(double %x, i1 %bool) {
+; CHECK-LABEL: @ldexp_zext_double(
+; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[BOOL:%.*]], double 2.000000e+00, double 1.000000e+00
+; CHECK-NEXT: [[LDEXP:%.*]] = fmul double [[TMP1]], [[X:%.*]]
+; CHECK-NEXT: ret double [[LDEXP]]
+;
+ %zext = zext i1 %bool to i32
+ %ldexp = call double @llvm.ldexp.f32.i32(double %x, i32 %zext)
+ ret double %ldexp
+}
+
+define double @ldexp_zext_double_fast_math(double %x, i1 %bool) {
+; CHECK-LABEL: @ldexp_zext_double_fast_math(
+; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[BOOL:%.*]], double 2.000000e+00, double 1.000000e+00
+; CHECK-NEXT: [[LDEXP:%.*]] = fmul fast double [[TMP1]], [[X:%.*]]
+; CHECK-NEXT: ret double [[LDEXP]]
+;
+ %zext = zext i1 %bool to i32
+ %ldexp = call fast double @llvm.ldexp.f32.i32(double %x, i32 %zext)
----------------
dtcxzyw wrote:
Don't use `fast` here. See https://llvm.org/docs/InstCombineContributorGuide.html#flag-tests
https://github.com/llvm/llvm-project/pull/94887
More information about the llvm-commits
mailing list