From 50e7d9797d9bf4b98a056d5df128c24dde6e78bd Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 23 Mar 2023 16:59:02 -0700 Subject: Fix optimization pass not converging. (#2725) * Fix optimization pass not converging. * Fix. * Fix tests. --------- Co-authored-by: Yong He --- source/slang/slang-ir.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-ir.cpp') diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 206d73e3f..69870c128 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -7093,8 +7093,6 @@ namespace Slang case kIROp_Add: case kIROp_Sub: case kIROp_Mul: - //case kIROp_Div: // TODO: We could split out integer vs. floating-point div/mod and assume the floating-point cases have no side effects - //case kIROp_Rem: case kIROp_Lsh: case kIROp_Rsh: case kIROp_Eql: @@ -7138,6 +7136,22 @@ namespace Slang case kIROp_BackwardDifferentiatePropagate: case kIROp_DetachDerivative: return false; + + case kIROp_Div: + case kIROp_IRem: + if (isIntegralScalarOrCompositeType(getFullType())) + { + if (auto intLit = as(getOperand(1))) + { + if (intLit->getValue() != 0) + return false; + } + return true; + } + return false; + + case kIROp_FRem: + return false; } return true; } -- cgit v1.2.3