This is an archive of the discontinued LLVM Phabricator instance.

Prevent Constant Folding From Optimizing inrange GEP
ClosedPublic

Authored by zhaomo on Sep 5 2018, 11:32 AM.

Details

Summary

This patch does the following things:

  1. update SymbolicallyEvaluateGEP so that it bails out if it cannot preserve inrange arribute;
  2. update llvm/test/Analysis/ConstantFolding/gep.ll to remove UB in it;
  3. remove inaccurate comment above ConstantFoldInstOperandsImpl in llvm/lib/Analysis/ConstantFolding.cpp;
  4. add a new regression test that makes sure that no optimizations change an inrange GEP in an unexpected way.

Diff Detail

Event Timeline

zhaomo created this revision.Sep 5 2018, 11:32 AM
zhaomo retitled this revision from Prevent Constant Folding Optimizes inrange GEP to Prevent Constant Folding From Optimizing inrange GEP.Sep 5 2018, 11:41 AM
pcc added inline comments.
llvm/lib/Analysis/ConstantFolding.cpp
985–986

I think this TODO is no longer accurate: we *are* being passed the instruction/constant in InstOrCE , so we end up preserving inbounds and inrange and could preserve nsw/nuw if we chose. I would remove it.

1001

Can this check be moved here?
http://llvm-cs.pcc.me.uk/lib/Analysis/ConstantFolding.cpp#957
I was imagining that if we fail to preserve inrange then we would return nullptr instead of dropping it.

zhaomo updated this revision to Diff 164105.Sep 5 2018, 1:36 PM
pcc added a comment.Sep 5 2018, 2:02 PM

Please update the commit message to reflect what this patch is now doing.

llvm/test/Analysis/ConstantFolding/gep.ll
10–11

Can you update the other tests to return the pointer instead of loading?

zhaomo updated this revision to Diff 164242.Sep 6 2018, 10:41 AM
zhaomo edited the summary of this revision. (Show Details)
zhaomo edited the summary of this revision. (Show Details)
pcc accepted this revision.Sep 10 2018, 6:45 PM

LGTM

This revision is now accepted and ready to land.Sep 10 2018, 6:45 PM
This revision was automatically updated to reflect the committed changes.