[PATCH] D68342: [Analysis] Don't assume that overflow can't happen in EmitGEPOffset
Mikhail Maltsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 2 09:56:50 PDT 2019
miyuki created this revision.
miyuki added reviewers: chandlerc, craig.topper, ostannard.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
Currently when computing a GEP offset using the function EmitGEPOffset
for the following instruction
getelementptr inbounds i32, i32* %p, i64 %offs
we get
mul nuw i64 %offs, 4
Unfortunately we cannot assume that unsigned wrapping won't happen
here because %offs is allowed to be negative. We also cannot assume
anything about signed wrapping because an object can be larger than
half of the corresponding address space (in which case when computing
a large positive offset the value will overflow into the sign bit).
Making such assumptions can lead to miscompilations: see the new test
test24_neg_offs in InstCombine/icmp.ll. Without the patch InstCombine
would generate the following comparison:
icmp eq i64 %offs, 4611686018427387902; 0x3ffffffffffffffe
Whereas the correct value to compare with is -2.
This patch removes the NUW flag from the multiplication instructions
generated by EmitGEPOffset and adjusts the test suite.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D68342
Files:
llvm/include/llvm/Analysis/Utils/Local.h
llvm/lib/Analysis/MemoryBuiltins.cpp
llvm/test/Transforms/InstCombine/gep-custom-dl.ll
llvm/test/Transforms/InstCombine/getelementptr.ll
llvm/test/Transforms/InstCombine/icmp-custom-dl.ll
llvm/test/Transforms/InstCombine/icmp.ll
llvm/test/Transforms/InstCombine/sub.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68342.222852.patch
Type: text/x-patch
Size: 13670 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191002/13598965/attachment.bin>
More information about the llvm-commits
mailing list