[llvm] [InstCombine] Don't folder select to or if value argument is user of invalid addrspacecast inst (PR #144686)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 18 23:40:14 PDT 2025
dtcxzyw wrote:
> > If an invalid addrspacecast can produce poison, then this must be specified in
> > https://github.com/llvm/llvm-project/blob/34a48941498d95ec2682f7adaeb6115b7b4d70ba/llvm/lib/Analysis/ValueTracking.cpp#L7352
>
> This PR uses isValidAddrSpaceCast query from TTI which is available in InstCombine. But TTI isn't available in above canCreateUndefOrPoison function. If we unconditionally return true for addrspacecast in canCreateUndefOrPoison, there is regression in following test probably because canCreateUndefOrPoison returning true for valid addrspacecast is preventing the optimization:
>
> https://github.com/llvm/llvm-project/blob/5875fafdc547889fb089c943a881a9ab6d8a23c0/llvm/test/Transforms/Attributor/reduced/aapointer_info_map_invalidation.ll#L4-L19
>
> > LangRef should also be adjusted in https://llvm.org/docs/LangRef.html#addrspacecast-to-instruction to specify that addrspacecast can introduce poison.
>
> done in [ffff2c3](https://github.com/llvm/llvm-project/commit/ffff2c3624239c1290e71abcce44f3317aab597a), please review
I don't think special handling of addrspacecast in `logical and/or->bitwise and/or` works. There are many places which call `isGuaranteedNotToBeUndefOrPoison`. For example, eliminating freeze from `freeze ptr (addrspacecast ptr addrspace(5) noundef %x to ptr)` is still invalid. That is, I can construct an input to bypass the workaround and cause the miscompilation.
It would be better to default to returning true for addrspacecast in `canCreateUndefOrPoison`, then add an optional callback for `isValidAddrSpaceCast` queries.
https://github.com/llvm/llvm-project/pull/144686
More information about the llvm-commits
mailing list