[llvm] r221318 - Analysis: Make isSafeToSpeculativelyExecute fire less for divides
Sanjoy Das
sanjoy at playingwithpointers.com
Sat Nov 8 16:59:03 PST 2014
Hi,
Just to be sure I understand the situation correctly: llvm concludes a
value to be non-zero or a poison value. The value cannot be poison
because if it is, any instruction that observes the poison will cause
undefined behavior (that may include propagating the poison value down
the use-def chain) and this "cannot happen". Thus it must be non-zero
or have no uses. So it is safe to conclude that it is non-zero.
> I doubt a correct implementation of isKnownNeverToBeUndef will ever fire
> because it must be incredibly conservative: function arguments might
> silently cary poison in them making them unsafe.
It feels like that "isKnownNotPoison" will have to be a path-sensitive
property. For example, the following case
void f(int x) {
if (x < 10) {
if (unknown) {
int t = 30 / x;
}
}
}
can be transformed to
void f(int x) {
if (x < 10) {
int t = 30 / x;
if (unknown) {
}
}
}
since x can't be poison after the `icmp` has been executed. LangRef
says:
1. "Values other than phi nodes depend on their operands."
2. "any instruction that has a dependence on a poison value has
undefined behavior."
"isKnownNeverToBeUndef" is distinct from "isKnownNotPoison", since not
every instruction consuming an undef has UB. For example the above
transform is not sound if `x` was `undef` (without "coercing" the
`undef` to some constant value) -- since it could then be `0`.
-- Sanjoy
More information about the llvm-commits
mailing list