[llvm] [EarlyCSE] Fix improper icmp simplification (PR #122043)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 8 00:21:49 PST 2025
llvmssh wrote:
> > > > https://godbolt.org/z/1MfndEMMs
> > >
> > >
> > > In this case, `%4` is passed into `_ZN1A5valueEv` which has `noundef` and `nonnull/dereferenceable` parameter attributes. The optimizer will assume `%4` is nonnull in the subsequent execution path.
> > > Without `noundef` and `nonnull/dereferenceable`, the icmp will not be optimized out: https://godbolt.org/z/chhxE3Txr
> >
> >
> > Yes, icmp is simplified with its information. Should we add the check of volatile to icmp simplify?
>
> I mean this transformation is correct. If the loaded pointer `%4` is nonnull, it hits UB when calling `_ZN1A5valueEv`.
> > > > https://godbolt.org/z/1MfndEMMs
> > >
> > >
> > > In this case, `%4` is passed into `_ZN1A5valueEv` which has `noundef` and `nonnull/dereferenceable` parameter attributes. The optimizer will assume `%4` is nonnull in the subsequent execution path.
> > > Without `noundef` and `nonnull/dereferenceable`, the icmp will not be optimized out: https://godbolt.org/z/chhxE3Txr
> >
> >
> > Yes, icmp is simplified with its information. Should we add the check of volatile to icmp simplify?
>
> I mean this transformation is correct. If the loaded pointer `%4` is nonnull, it hits UB when calling `_ZN1A5valueEv`.
In actual testing, no matter if % 4 is set to null in a multithreaded environment, it seems that there is no running problem when calling _ZN1A5valueEv. Due to optimizations, %4 == null cannot be intercepted.
https://github.com/llvm/llvm-project/pull/122043
More information about the llvm-commits
mailing list