[PATCH] D22942: [SCEV] Fix runtime error caused by ValueOffsetPair

Wei Mi via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 28 14:51:39 PDT 2016


wmi created this revision.
wmi added a reviewer: sanjoy.
wmi added subscribers: llvm-commits, davidxl, hans.
wmi set the repository for this revision to rL LLVM.
Herald added subscribers: mzolotukhin, sanjoy.

The patch is to fix the bug in https://llvm.org/bugs/show_bug.cgi?id=28705

Previously in SCEVExpander::findExistingExpansion, we returned the value part of the ValueOffsetPair returned by FindValueInExprValueMap directly no matter whether the offset is zero or not. I mistakenly thought SCEVExpander::findExistingExpansion was only used to check whether there was an existing value to be reused (This is true for all its uses in lib/Analysis/ScalarEvolutionExpander.cpp). I missed the fact that SCEVExpander::findExistingExpansion was also used in IndVarSimplify::expandSCEVIfNeeded and the value returned was used to replace exit value of induction variable in IndVarSimplify. It caused IndVarSimplify used a wrong value as the exit value of induction variable (The correct value should be "value - offset" expr).

The fix is to add an OnlyCheckIsNull param for SCEVExpander::findExistingExpansion. If OnlyCheckIsNull is false and ValueOffsetPair returned by FindValueInExprValueMap contains a non-zero offset, we will return nullptr. So that IndVarSimplify::expandSCEVIfNeeded will continue to use SCEVExpander::expandCodeFor to do the expansion. 

I don't want SCEVExpander::findExistingExpansion to insert the "Value - Offset" expr based on ValueOffsetPair because it can insert the expr inside the loop. SCEVExpander::expandCodeFor contains the logic to choose a better insert point. 

Repository:
  rL LLVM

https://reviews.llvm.org/D22942

Files:
  include/llvm/Analysis/ScalarEvolutionExpander.h
  lib/Analysis/ScalarEvolutionExpander.cpp
  lib/Transforms/Scalar/IndVarSimplify.cpp
  test/Analysis/ScalarEvolution/pr28705.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22942.66000.patch
Type: text/x-patch
Size: 4467 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160728/ebc7afcf/attachment.bin>


More information about the llvm-commits mailing list