[llvm] InstSimplify: support floating-point equivalences (PR #115152)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 7 08:11:57 PST 2024
================
@@ -0,0 +1,156 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
+
+define float @select_fcmp_fsub_oeq(float %x, float %y) {
+; CHECK-LABEL: @select_fcmp_fsub_oeq(
+; CHECK-NEXT: ret float 0.000000e+00
+;
+ %fcmp = fcmp oeq float %y, 2.
+ %fadd = fsub float %y, 2.
+ %sel = select i1 %fcmp, float %fadd, float 0.
+ ret float %sel
+}
+
+define float @select_fcmp_fsub_oeq_zero(float %x, float %y) {
+; CHECK-LABEL: @select_fcmp_fsub_oeq_zero(
+; CHECK-NEXT: [[FCMP:%.*]] = fcmp oeq float [[Y:%.*]], 0.000000e+00
+; CHECK-NEXT: [[FADD:%.*]] = fsub float [[Y]], 2.000000e+00
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[FCMP]], float [[FADD]], float 2.000000e+00
+; CHECK-NEXT: ret float [[SEL]]
+;
+ %fcmp = fcmp oeq float %y, 0.
+ %fadd = fsub float %y, 2.
+ %sel = select i1 %fcmp, float %fadd, float 2.
+ ret float %sel
+}
+
+define float @select_fcmp_fsub_ueq(float %x, float %y) {
+; CHECK-LABEL: @select_fcmp_fsub_ueq(
+; CHECK-NEXT: [[FCMP:%.*]] = fcmp ueq float [[Y:%.*]], 2.000000e+00
+; CHECK-NEXT: [[FADD:%.*]] = fsub float [[Y]], 2.000000e+00
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[FCMP]], float [[FADD]], float 0.000000e+00
+; CHECK-NEXT: ret float [[SEL]]
+;
+ %fcmp = fcmp ueq float %y, 2.
+ %fadd = fsub float %y, 2.
+ %sel = select i1 %fcmp, float %fadd, float 0.
+ ret float %sel
+}
+
+define float @select_fcmp_fsub_ueq_nnan(float %x, float %y) {
+; CHECK-LABEL: @select_fcmp_fsub_ueq_nnan(
+; CHECK-NEXT: ret float 0.000000e+00
+;
+ %fcmp = fcmp nnan ueq float %y, 2.
+ %fadd = fsub float %y, 2.
+ %sel = select i1 %fcmp, float %fadd, float 0.
+ ret float %sel
+}
+
+define float @select_fcmp_fsub_une(float %x, float %y) {
+; CHECK-LABEL: @select_fcmp_fsub_une(
+; CHECK-NEXT: ret float 0.000000e+00
+;
+ %fcmp = fcmp une float %y, 2.
+ %fadd = fsub float %y, 2.
+ %sel = select i1 %fcmp, float 0., float %fadd
+ ret float %sel
+}
+
+define float @select_fcmp_fsub_une_zero(float %x, float %y) {
+; CHECK-LABEL: @select_fcmp_fsub_une_zero(
+; CHECK-NEXT: [[FCMP:%.*]] = fcmp une float [[Y:%.*]], 0.000000e+00
+; CHECK-NEXT: [[FADD:%.*]] = fsub float [[Y]], 2.000000e+00
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[FCMP]], float 2.000000e+00, float [[FADD]]
+; CHECK-NEXT: ret float [[SEL]]
+;
+ %fcmp = fcmp une float %y, 0.
+ %fadd = fsub float %y, 2.
+ %sel = select i1 %fcmp, float 2., float %fadd
+ ret float %sel
+}
+
+define float @select_fcmp_fsub_one(float %x, float %y) {
+; CHECK-LABEL: @select_fcmp_fsub_one(
+; CHECK-NEXT: [[FCMP:%.*]] = fcmp one float [[Y:%.*]], 2.000000e+00
+; CHECK-NEXT: [[FADD:%.*]] = fsub float [[Y]], 2.000000e+00
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[FCMP]], float 0.000000e+00, float [[FADD]]
+; CHECK-NEXT: ret float [[SEL]]
+;
+ %fcmp = fcmp one float %y, 2.
+ %fadd = fsub float %y, 2.
----------------
arsenm wrote:
Put some 0s after all the decimals throughout
https://github.com/llvm/llvm-project/pull/115152
More information about the llvm-commits
mailing list