[PATCH] D116332: [ConstantFold] Make icmp of gep fold offset based
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 28 05:41:32 PST 2021
nikic created this revision.
nikic added reviewers: opaque-pointers, spatel, lebedev.ri.
Herald added subscribers: dexonsmith, hiraditya.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
We can fold an equality or unsigned icmp between `base+offset1` and `base+offset2` with inbounds offsets by comparison the offsets directly.
This replaces a pair of specialized folds that tried to reason based on the GEP structure instead. One of those folds was plain wrong (because it does not account for negative offsets), while the other is unnecessarily complicated and limited (e.g. it will fail with bitcasts involved).
The disadvantage of this change is that it requires data layout, so the fold is no longer performed by datalayout-independent constant folding. I don't think this is a loss in practice, but it does regress the ConstantExprFold.ll test, which checks folding without running any passes.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D116332
Files:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/lib/IR/ConstantFold.cpp
llvm/test/Assembler/ConstantExprFold.ll
llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116332.396391.patch
Type: text/x-patch
Size: 9327 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211228/9de5e071/attachment.bin>
More information about the llvm-commits
mailing list