[llvm] ad3ad15 - [InstCombine] Test for fmod -> frem folding. NFC

David Green via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 12 13:10:45 PDT 2024


Author: David Green
Date: 2024-09-12T21:10:40+01:00
New Revision: ad3ad15229cc65874eae173137e47b5c817d77ea

URL: https://github.com/llvm/llvm-project/commit/ad3ad15229cc65874eae173137e47b5c817d77ea
DIFF: https://github.com/llvm/llvm-project/commit/ad3ad15229cc65874eae173137e47b5c817d77ea.diff

LOG: [InstCombine] Test for fmod -> frem folding. NFC

Added: 
    llvm/test/Transforms/InstCombine/fmod.ll

Modified: 
    llvm/test/Transforms/InstCombine/pow-1.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/fmod.ll b/llvm/test/Transforms/InstCombine/fmod.ll
new file mode 100644
index 00000000000000..c021d27e95fa5e
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/fmod.ll
@@ -0,0 +1,128 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt -S -passes=instcombine < %s | FileCheck %s
+
+define float @test_inf_const(float %f) {
+; CHECK-LABEL: define float @test_inf_const(
+; CHECK-SAME: float [[F:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[ABS:%.*]] = tail call float @llvm.fabs.f32(float [[F]])
+; CHECK-NEXT:    [[ISINF:%.*]] = fcmp oeq float [[ABS]], 0x7FF0000000000000
+; CHECK-NEXT:    br i1 [[ISINF]], label [[RETURN:%.*]], label [[IF_END:%.*]]
+; CHECK:       if.end:
+; CHECK-NEXT:    [[CALL:%.*]] = tail call float @fmodf(float [[F]], float 2.000000e+00)
+; CHECK-NEXT:    ret float [[CALL]]
+; CHECK:       return:
+; CHECK-NEXT:    ret float 0.000000e+00
+;
+entry:
+  %abs = tail call float @llvm.fabs.f32(float %f)
+  %isinf = fcmp oeq float %abs, 0x7FF0000000000000
+  br i1 %isinf, label %return, label %if.end
+
+if.end:
+  %call = tail call float @fmodf(float %f, float 2.0)
+  ret float %call
+
+return:
+  ret float 0.0
+}
+
+define float @test_const_zero(float %f) {
+; CHECK-LABEL: define float @test_const_zero(
+; CHECK-SAME: float [[F:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[ISZERO:%.*]] = fcmp oeq float [[F]], 0.000000e+00
+; CHECK-NEXT:    br i1 [[ISZERO]], label [[RETURN:%.*]], label [[IF_END:%.*]]
+; CHECK:       if.end:
+; CHECK-NEXT:    [[CALL:%.*]] = tail call float @fmodf(float 2.000000e+00, float [[F]])
+; CHECK-NEXT:    ret float [[CALL]]
+; CHECK:       return:
+; CHECK-NEXT:    ret float 0.000000e+00
+;
+entry:
+  %iszero = fcmp oeq float %f, 0.0
+  br i1 %iszero, label %return, label %if.end
+
+if.end:
+  %call = tail call float @fmodf(float 2.0, float %f)
+  ret float %call
+
+return:
+  ret float 0.0
+}
+
+define float @test_unknown_const(float %f) {
+; CHECK-LABEL: define float @test_unknown_const(
+; CHECK-SAME: float [[F:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CALL:%.*]] = tail call float @fmodf(float [[F]], float 2.000000e+00)
+; CHECK-NEXT:    ret float [[CALL]]
+;
+entry:
+  %call = tail call float @fmodf(float %f, float 2.000000e+00)
+  ret float %call
+}
+
+define float @test_noinf_nozero(float nofpclass(inf) %f, float nofpclass(zero) %g) {
+; CHECK-LABEL: define float @test_noinf_nozero(
+; CHECK-SAME: float nofpclass(inf) [[F:%.*]], float nofpclass(zero) [[G:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CALL:%.*]] = tail call nnan float @fmodf(float [[F]], float [[G]])
+; CHECK-NEXT:    ret float [[CALL]]
+;
+entry:
+  %call = tail call nnan float @fmodf(float %f, float %g)
+  ret float %call
+}
+
+define double @test_double(double nofpclass(inf) %f, double nofpclass(zero) %g) {
+; CHECK-LABEL: define double @test_double(
+; CHECK-SAME: double nofpclass(inf) [[F:%.*]], double nofpclass(zero) [[G:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CALL:%.*]] = tail call double @fmod(double [[F]], double [[G]])
+; CHECK-NEXT:    ret double [[CALL]]
+;
+entry:
+  %call = tail call double @fmod(double %f, double %g)
+  ret double %call
+}
+
+define fp128 @test_fp128(fp128 nofpclass(inf) %f, fp128 nofpclass(zero) %g) {
+; CHECK-LABEL: define fp128 @test_fp128(
+; CHECK-SAME: fp128 nofpclass(inf) [[F:%.*]], fp128 nofpclass(zero) [[G:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CALL:%.*]] = tail call fp128 @fmodl(fp128 [[F]], fp128 [[G]])
+; CHECK-NEXT:    ret fp128 [[CALL]]
+;
+entry:
+  %call = tail call fp128 @fmodl(fp128 %f, fp128 %g)
+  ret fp128 %call
+}
+
+define float @test_noinf_nozero_dazpreservesign(float nofpclass(inf) %f, float nofpclass(zero) %g) "denormal-fp-math"="preserve-sign,preserve-sign" {
+; CHECK-LABEL: define float @test_noinf_nozero_dazpreservesign(
+; CHECK-SAME: float nofpclass(inf) [[F:%.*]], float nofpclass(zero) [[G:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CALL:%.*]] = tail call nnan float @fmodf(float [[F]], float [[G]])
+; CHECK-NEXT:    ret float [[CALL]]
+;
+entry:
+  %call = tail call nnan float @fmodf(float %f, float %g)
+  ret float %call
+}
+
+define float @test_noinf_nozero_dazdynamic(float nofpclass(inf) %f, float nofpclass(zero) %g) "denormal-fp-math"="dynamic,dynamic" {
+; CHECK-LABEL: define float @test_noinf_nozero_dazdynamic(
+; CHECK-SAME: float nofpclass(inf) [[F:%.*]], float nofpclass(zero) [[G:%.*]]) #[[ATTR1:[0-9]+]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CALL:%.*]] = tail call nnan float @fmodf(float [[F]], float [[G]])
+; CHECK-NEXT:    ret float [[CALL]]
+;
+entry:
+  %call = tail call nnan float @fmodf(float %f, float %g)
+  ret float %call
+}
+
+declare float @fmodf(float, float)
+declare double @fmod(double, double)
+declare fp128 @fmodl(fp128, fp128)

diff  --git a/llvm/test/Transforms/InstCombine/pow-1.ll b/llvm/test/Transforms/InstCombine/pow-1.ll
index 44802f9caa6ea5..f4bbd3eb46bf79 100644
--- a/llvm/test/Transforms/InstCombine/pow-1.ll
+++ b/llvm/test/Transforms/InstCombine/pow-1.ll
@@ -862,6 +862,30 @@ define double @pow_libcall_half_no_FMF(double %x) {
   ret double %retval
 }
 
+define double @pow_libcall_half_fromdomcondition(double %x) {
+; CHECK-LABEL: define double @pow_libcall_half_fromdomcondition(
+; CHECK-SAME: double [[X:%.*]]) {
+; CHECK-NEXT:    [[A:%.*]] = call double @llvm.fabs.f64(double [[X]])
+; CHECK-NEXT:    [[C:%.*]] = fcmp oeq double [[A]], 0x7FF0000000000000
+; CHECK-NEXT:    br i1 [[C]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK:       then:
+; CHECK-NEXT:    ret double 0.000000e+00
+; CHECK:       else:
+; CHECK-NEXT:    [[RETVAL:%.*]] = call double @pow(double [[X]], double 5.000000e-01)
+; CHECK-NEXT:    ret double [[RETVAL]]
+;
+  %a = call double @llvm.fabs.f64(double %x)
+  %c = fcmp oeq double %a, 0x7FF0000000000000
+  br i1 %c, label %then, label %else
+
+then:
+  ret double 0.0
+
+else:
+  %retval = call double @pow(double %x, double 0.5)
+  ret double %retval
+}
+
 define double @pow_libcall_half_no_FMF_noerrno(double %x) {
 ; LIB-LABEL: define double @pow_libcall_half_no_FMF_noerrno(
 ; LIB-SAME: double [[X:%.*]]) {


        


More information about the llvm-commits mailing list