From 66c2976186f5b874c3948cd56f7ded3672ecb726 Mon Sep 17 00:00:00 2001 From: Henry Zongaro Date: Wed, 7 Sep 2022 10:51:51 -0700 Subject: [PATCH] Check whether array index variable is an induction variable In examining an array index for Idiom Recognition, analyzeOneArrayIndex checks whether the variable operand in a 'var + const' or 'const + var' expression is an induction variable. On the other hand, if the expression is a simple variable, the analysis assumes the variable reference is acceptable. However, it can happen that the variable used as the array index is not an induction variable which can result in an incorrect transformation. Fixed this by adding a check that an arrayindex that is a variable is also an induction variable. Fixes #15474 Signed-off-by: Henry Zongaro --- runtime/compiler/optimizer/IdiomRecognition.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/runtime/compiler/optimizer/IdiomRecognition.cpp b/runtime/compiler/optimizer/IdiomRecognition.cpp index c5dba1c7861..eca95853bc2 100644 --- a/runtime/compiler/optimizer/IdiomRecognition.cpp +++ b/runtime/compiler/optimizer/IdiomRecognition.cpp @@ -7162,7 +7162,15 @@ TR_CISCTransformer::analyzeOneArrayIndex(TR_CISCNode *arrayindex, TR::SymbolRefe } if (!ret) return false; } - else if (t->getOpcode() != TR_variable) + else if (t->getOpcode() == TR_variable) + { + TR::SymbolReference *symref = t->getHeadOfTrNodeInfo()->_node->getSymbolReference(); + if (symref != inductionVariableSymRef) + { + return false; + } + } + else { return false; }