From 519cd873c79c58e003c77c59356456e0eaed4036 Mon Sep 17 00:00:00 2001 From: "Paige, Alexander" Date: Tue, 12 Sep 2023 19:16:18 -0700 Subject: [PATCH] [Autobackout][FuncReg]Revert of change: a4b3b5b1101c5b280b90825ef06596d29c9163f2 Initialize new FastMathConstantHandling pass This pass solves the issues where the fast math flags on the instruction do not match the immediate constants on that instruction. If we don't match this we can get wrong behavior later in instcombine --- .../FastMathConstantHandling.cpp | 103 ------------------ IGC/AdaptorCommon/FastMathConstantHandling.h | 19 ---- IGC/DriverInterface/CMakeLists.txt | 2 - IGC/common/igc_flags.h | 1 - 4 files changed, 125 deletions(-) delete mode 100644 IGC/AdaptorCommon/FastMathConstantHandling.cpp delete mode 100644 IGC/AdaptorCommon/FastMathConstantHandling.h diff --git a/IGC/AdaptorCommon/FastMathConstantHandling.cpp b/IGC/AdaptorCommon/FastMathConstantHandling.cpp deleted file mode 100644 index 485b8844dec5..000000000000 --- a/IGC/AdaptorCommon/FastMathConstantHandling.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/*========================== begin_copyright_notice ============================ - -Copyright (C) 2023 Intel Corporation - -SPDX-License-Identifier: MIT - -============================= end_copyright_notice ===========================*/ - -#include "common/LLVMWarningsPush.hpp" -#include -#include -#include -#include "common/LLVMWarningsPop.hpp" -#include "FastMathConstantHandling.h" -#include "Compiler/IGCPassSupport.h" -#include "common/igc_regkeys.hpp" - -using namespace llvm; -namespace IGC -{ - -class FastMathConstantHandling : public FunctionPass, public InstVisitor -{ -public: - FastMathConstantHandling(); - ~FastMathConstantHandling() {} - static char ID; - bool runOnFunction(Function& F) override; - void visitInstruction(Instruction& I); - virtual llvm::StringRef getPassName() const override { return "Fast Math Constant Handling"; } - - void getAnalysisUsage(AnalysisUsage& AU) const override - { - AU.setPreservesCFG(); - } -}; - -#define PASS_FLAG "FastMathConstantHandling" -#define PASS_DESC "Fast Math Constant Handling" -#define PASS_CFG_ONLY false -#define PASS_ANALYSIS false -IGC_INITIALIZE_PASS_BEGIN(FastMathConstantHandling, PASS_FLAG, PASS_DESC, PASS_CFG_ONLY, PASS_ANALYSIS) -IGC_INITIALIZE_PASS_END(FastMathConstantHandling, PASS_FLAG, PASS_DESC, PASS_CFG_ONLY, PASS_ANALYSIS) - -char FastMathConstantHandling::ID = 0; - -FastMathConstantHandling::FastMathConstantHandling() - :FunctionPass(ID) -{ - initializeFastMathConstantHandlingPass(*PassRegistry::getPassRegistry()); -} - -// This purpose of this pass is to catch bad fast flag management where we are seeing -// constants that are not matching the fast flags that are set on the instructions - -void FastMathConstantHandling::visitInstruction(Instruction& I) -{ - if (isa(I)) - { - struct BoolSpecialConstants { - bool hasInf = false; - bool hasNan = false; - bool hasNegZero = false; - } BSC; - - for (auto &Op : I.operands()) - { - if (auto* fp_val = dyn_cast(Op)) - { - auto APF = fp_val->getValueAPF(); - BSC.hasInf |= APF.isInfinity(); - BSC.hasNan |= APF.isNaN(); - BSC.hasNegZero |= APF.isNegZero(); - } - } - - if (BSC.hasInf) - I.setHasNoInfs(false); - - if (BSC.hasNan) - I.setHasNoNaNs(false); - - if (BSC.hasNegZero) - I.setHasNoSignedZeros(false); - } -} - -bool FastMathConstantHandling::runOnFunction(Function& F) -{ - if (IGC_IS_FLAG_DISABLED(DisableFastMathConstantHandling)) - { - visit(F); - } - return true; -} - - -FunctionPass* createFastMathConstantHandling() -{ - return new FastMathConstantHandling(); -} - -}//namespace IGC diff --git a/IGC/AdaptorCommon/FastMathConstantHandling.h b/IGC/AdaptorCommon/FastMathConstantHandling.h deleted file mode 100644 index 5f37abba6817..000000000000 --- a/IGC/AdaptorCommon/FastMathConstantHandling.h +++ /dev/null @@ -1,19 +0,0 @@ -/*========================== begin_copyright_notice ============================ - -Copyright (C) 2023 Intel Corporation - -SPDX-License-Identifier: MIT - -============================= end_copyright_notice ===========================*/ - -#pragma once - -#include "common/LLVMWarningsPush.hpp" -#include "llvm/Pass.h" -#include "common/LLVMWarningsPop.hpp" - -namespace IGC -{ - void initializeFastMathConstantHandlingPass(llvm::PassRegistry&); - llvm::FunctionPass* createFastMathConstantHandling(); -} diff --git a/IGC/DriverInterface/CMakeLists.txt b/IGC/DriverInterface/CMakeLists.txt index 021ec5df7aea..0fdaa67762e7 100644 --- a/IGC/DriverInterface/CMakeLists.txt +++ b/IGC/DriverInterface/CMakeLists.txt @@ -20,7 +20,6 @@ set(IGC_BUILD__SRC__DriverInterface "${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorCommon/TypesLegalizationPass.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorCommon/LegalizeFunctionSignatures.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorCommon/DivergentBarrierPass.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorCommon/FastMathConstantHandling.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorOCL/OCL/LoadBuffer.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorOCL/OCL/Patch/patch_parser.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorOCL/OCL/Platform/cmd_media_caps_g8.cpp" @@ -84,7 +83,6 @@ endif(IGC_BUILD__SPIRV_ENABLED) set(IGC_BUILD__HDR__DriverInterface "${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorCommon/customApi.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorCommon/DivergentBarrierPass.h" - "${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorCommon/FastMathConstantHandling.h" "${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorOCL/OCL/KernelAnnotations.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorOCL/OCL/CommandStream/SamplerTypes.h" "${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorOCL/OCL/CommandStream/SurfaceTypes.h" diff --git a/IGC/common/igc_flags.h b/IGC/common/igc_flags.h index 6e09b7eeea26..47dd2b661883 100644 --- a/IGC/common/igc_flags.h +++ b/IGC/common/igc_flags.h @@ -759,7 +759,6 @@ DECLARE_IGC_REGKEY(bool, OverrideCsTileLayout, 0, "Override compute wa DECLARE_IGC_REGKEY(DWORD, MemCpyLoweringUnrollThreshold, 12, "Min number of mem instructions that require non-unrolled loop when lowering memcpy", false) DECLARE_IGC_REGKEY(bool, EnableSOAPromotionDisablingHeuristic, false, "Enable heuristic to disable SOA promotion when it may be not beneficial", false) DECLARE_IGC_REGKEY(bool, EnableCSContentCheck, false, "Enable CS content check to force SIMD32", true) -DECLARE_IGC_REGKEY(bool, DisableFastMathConstantHandling, false, "Disable Fast Math Constant Handling", true) DECLARE_IGC_GROUP("Generating precompiled headers") DECLARE_IGC_REGKEY(bool, ApplyConservativeRastWAHeader, true, "Apply WaConservativeRasterization for the platforms enabled", false)