summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-peephole.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-05-10 09:11:36 -0700
committerGitHub <noreply@github.com>2023-05-10 09:11:36 -0700
commitc8e6a6452f4e531dca09152178bae2f9a2fb999a (patch)
treedab0f646dc520d2a187f64885e7b7fe152b49f5e /source/slang/slang-ir-peephole.cpp
parentddebd60853b3f34bfd8e89de804fd15808abf75d (diff)
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 <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-peephole.cpp')
-rw-r--r--source/slang/slang-ir-peephole.cpp68
1 files changed, 0 insertions, 68 deletions
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<IRIntLit>(inst)->getValue() == 0;
- case kIROp_FloatLit:
- return as<IRFloatLit>(inst)->getValue() == 0.0;
- case kIROp_BoolLit:
- return as<IRBoolLit>(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<IRIntLit>(inst)->getValue() == 1;
- case kIROp_FloatLit:
- return as<IRFloatLit>(inst)->getValue() == 1.0;
- case kIROp_BoolLit:
- return as<IRBoolLit>(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 =