[PATCH] D128647: [InstructionSimplify] handle denormal constant input for fcmp

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 29 07:27:50 PDT 2022


spatel added inline comments.


================
Comment at: llvm/lib/Analysis/ConstantFolding.cpp:1394
+        Constant *Op0 =
+            isa<ConstantFP>(LHS)
+                ? FlushFPConstant(
----------------
Prefer dyn_cast rather than isa+cast. So it could be written like this:

        // Flush denormal inputs if needed.
        if (auto *LCFP = dyn_cast<ConstantFP>(LHS)) {
          const fltSemantics &FltSema = LCFP->getType()->getFltSemantics();
          LHS = FlushFPConstant(LCFP, F->getDenormalMode(FltSema).Input);
        }
        if (auto *RCFP = dyn_cast<ConstantFP>(RHS)) {
          const fltSemantics &FltSema = RCFP->getType()->getFltSemantics();
          RHS = FlushFPConstant(RCFP, F->getDenormalMode(FltSema).Input);
        }

        // Calculate constant result.
        Constant *C = ConstantFoldBinaryOpOperands(Opcode, LHS, RHS, DL);

        // Flush denormal output if needed.
        if (auto *CFP = dyn_cast<ConstantFP>(C)) {
          const fltSemantics &FltSema = CFP->getType()->getFltSemantics();
          C = FlushFPConstant(CFP, F->getDenormalMode(FltSema).Output);
        }

        return C;



================
Comment at: llvm/test/Transforms/InstSimplify/constant-fold-fp-denormal.ll:763
 
 define i1 @fcmp_double_positive_zero() #6 {
 ; CHECK-LABEL: @fcmp_double_positive_zero(
----------------
Please add more tests to verify that we have the expected behavior for other denormal modes. These would be similar to what was added with D116952 (see tests in this file above here).


================
Comment at: llvm/test/Transforms/InstSimplify/constant-fold-fp-denormal.ll:773
 
 define i1 @fcmp_float_positive_zero() #6 {
 ; CHECK-LABEL: @fcmp_float_positive_zero(
----------------
This is identical to the previous test?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128647/new/

https://reviews.llvm.org/D128647



More information about the llvm-commits mailing list