[all-commits] [llvm/llvm-project] 597946: [ConstantFold] Don't convert getelementptr to ptrt...
Nikita Popov via All-commits
all-commits at lists.llvm.org
Mon May 2 01:25:05 PDT 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 597946a4dd2b3ba213f08a18285ab4362f873aa8
https://github.com/llvm/llvm-project/commit/597946a4dd2b3ba213f08a18285ab4362f873aa8
Author: Nikita Popov <npopov at redhat.com>
Date: 2022-05-02 (Mon, 02 May 2022)
Changed paths:
M llvm/lib/Analysis/ConstantFolding.cpp
M llvm/test/Transforms/InstCombine/constant-fold-gep.ll
Log Message:
-----------
[ConstantFold] Don't convert getelementptr to ptrtoint+inttoptr
ConstantFolding currently converts "getelementptr i8, Ptr, (sub 0, V)"
to "inttoptr (sub (ptrtoint Ptr), V)". This transform is, taken by
itself, correct, but does came with two issues:
1. It unnecessarily broadens provenance by introducing an inttoptr.
We generally prefer not to introduce inttoptr during optimization.
2. For the case where V == ptrtoint Ptr, this folds to inttoptr 0,
which further folds to null. In that case provenance becomes
incorrect. This has been observed as a real-world miscompile with
rustc.
We should probably address that incorrect inttoptr 0 fold at some
point, but in either case we should also drop this inttoptr-introducing
fold. Instead, replace it with a fold rooted at
ptrtoint(getelementptr), which seems to cover the original
motivation for this fold (test2 in the changed file).
Differential Revision: https://reviews.llvm.org/D124677
More information about the All-commits
mailing list