[PATCH] D54170: [InstCombine][SelectionDAG][AArch64] fold gep into select to enable speculation of load

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 6 14:35:37 PST 2018


efriedma added inline comments.


================
Comment at: test/Transforms/InstCombine/gep-select.ll:29
+  %sel = select i1 %cmp, i32* %gep1, i32* %gep2
+  %ld = load i32, i32* %sel, align 4
+  ret i32 %ld
----------------
labrinea wrote:
> efriedma wrote:
> > I'm pretty sure this isn't safe, in general.  The "inbounds" marker only guarantees that the arithmetic is in bounds; it doesn't make any guarantees about the type of the pointer.
> My comment was not referring to the inbounds marker. I am actually looking whether the indices derived from the select fall into the boundaries of a static type. In this example the last index of the geps ( `i32 1` and `i32 2` respectively) indicate valid offsets of struct members (the last two i32 members of struct.A).
The static type of a pointer or GEP can't be used to prove anything about the memory it points to.  In C, accessing a member does imply the base pointer points to a valid struct, but we don't record that anywhere in IR. (IIRC there was some discussion of trying to add metadata to model this, but it never went anywhere.)


https://reviews.llvm.org/D54170





More information about the llvm-commits mailing list