[PATCH] D98391: [InstSimplify] Set UseInstrInfo to false when calling SimplifyWithOpReplaced

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 10 21:19:37 PST 2021


aqjune created this revision.
aqjune added reviewers: nikic, spatel, lebedev.ri.
Herald added subscribers: dexonsmith, hiraditya.
aqjune requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

`SimplifyWithOpReplaced` has `AllowRefinement` argument, but when it further calls `SimplifyXXX`,
the flag isn't properly passed.
This causes the simplifying calls to fold possibly-poison values into non-poison constant
even if `AllowRefinement` is set to false.

This causes miscompilation https://llvm.org/pr49495.
`simplifySelectWithICmpCond` calls `SimplifyWithOpReplaced` with `AllowRefinement` set to false.
However, the information is lost, causing `computePointerICmp` to do folding based on `inbounds` flag.
`computePointerICmp` transforms `(gep inbounds x, -1) >u x` into `-1 >s 0` which is correct only if
inbounds is set (https://alive2.llvm.org/ce/z/mGwYxH vs. https://alive2.llvm.org/ce/z/e-2KQh ).

To fix this, this patch updates `simplifySelectWithICmpCond` to call `SimplifyWithOpReplaced` with `Q.getWithoutRefinement()`.
`SimplifyQuery::getWithoutRefinement()` is a new method that simply returns a new object with
existing `IIQ.UseInstrInfo` and `CanUseUndef` set to false..
If this flag is set, simplification cannot fold undef constant or exploit nsw/inbounds/... flags.
With this update, the refinement information is properly propagated to callees because `IIQ.UseInstrInfo`
is already used widely.

This wasn't enough to fix the pointer folding, and I updated `computePointerICmp` and its relevant calls
to respect `IIQ.UseInstrInfo`. The updates in Value.h/cpp are for this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98391

Files:
  llvm/include/llvm/Analysis/InstructionSimplify.h
  llvm/include/llvm/IR/Value.h
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/lib/IR/Value.cpp
  llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
  llvm/test/Transforms/InstCombine/select.ll
  llvm/test/Transforms/InstSimplify/pr49495.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98391.329838.patch
Type: text/x-patch
Size: 17724 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210311/12709eeb/attachment.bin>


More information about the llvm-commits mailing list