From c8e6a6452f4e531dca09152178bae2f9a2fb999a Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 10 May 2023 09:11:36 -0700 Subject: Generate faster derivative for div by const operations. (#2877) * Generate faster derivative for div by const operations. * Increase `kMaxIterationsToAttempt` to 256. --------- Co-authored-by: Yong He --- source/slang/slang-ir-peephole.cpp | 68 -------------------------------------- 1 file changed, 68 deletions(-) (limited to 'source/slang/slang-ir-peephole.cpp') diff --git a/source/slang/slang-ir-peephole.cpp b/source/slang/slang-ir-peephole.cpp index f04012112..e07d1f9c4 100644 --- a/source/slang/slang-ir-peephole.cpp +++ b/source/slang/slang-ir-peephole.cpp @@ -112,74 +112,6 @@ struct PeepholeContext : InstPassBase return false; } - bool isZero(IRInst* inst) - { - switch (inst->getOp()) - { - case kIROp_IntLit: - return as(inst)->getValue() == 0; - case kIROp_FloatLit: - return as(inst)->getValue() == 0.0; - case kIROp_BoolLit: - return as(inst)->getValue() == false; - case kIROp_MakeVector: - case kIROp_MakeVectorFromScalar: - case kIROp_MakeMatrix: - case kIROp_MakeMatrixFromScalar: - case kIROp_MatrixReshape: - case kIROp_VectorReshape: - { - for (UInt i = 0; i < inst->getOperandCount(); i++) - { - if (!isZero(inst->getOperand(i))) - { - return false; - } - } - return true; - } - case kIROp_CastIntToFloat: - case kIROp_CastFloatToInt: - return isZero(inst->getOperand(0)); - default: - return false; - } - } - - bool isOne(IRInst* inst) - { - switch (inst->getOp()) - { - case kIROp_IntLit: - return as(inst)->getValue() == 1; - case kIROp_FloatLit: - return as(inst)->getValue() == 1.0; - case kIROp_BoolLit: - return as(inst)->getValue(); - case kIROp_MakeVector: - case kIROp_MakeVectorFromScalar: - case kIROp_MakeMatrix: - case kIROp_MakeMatrixFromScalar: - case kIROp_MatrixReshape: - case kIROp_VectorReshape: - { - for (UInt i = 0; i < inst->getOperandCount(); i++) - { - if (!isOne(inst->getOperand(i))) - { - return false; - } - } - return true; - } - case kIROp_CastIntToFloat: - case kIROp_CastFloatToInt: - return isOne(inst->getOperand(0)); - default: - return false; - } - } - bool tryOptimizeArithmeticInst(IRInst* inst) { bool allowUnsafeOptimizations = -- cgit v1.2.3