[llvm] [ConstantFold][RFC] Fold special constant value with binop absorber f… (PR #109736)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 24 03:04:49 PDT 2024


eric-xtang1008 wrote:

Thanks.
> > The different result is that clang will optimize the result to poison, but hardware doesn't.
> 
> What the hardware does here is not relevant, only the semantics specified in LangRef are relevant. 

Yes, that's good point. I misunderstood before.

> Doing what you're doing here may look like it "fixes" the problem, but as long as your input contains undefined behavior, there will always be more cases where is "misbehaves".

In my understand, the input may be constant, undef and posion value in this condition, so how to understand undefined behavior? 
> 
> Adding LHS support to getBinOpAbsorber() by itself is a reasonable idea, but it would have to be implemented in a way that _preserves_ the current behavior for poison.

Yes, this patch changed the behavior of poison, but only for special value(0 & -1) in some special binary ops(Or, And, Mul, Shfit), like as `0 * poison = 0`. In my mind, 0 multily any integer number equal 0, but before this patch,  `0 * poison = poison`, so how to understand `0 * poison = poison`?

For shift, this change  `(0 << -1 = 0)` could be right? (before it's  `(0 << -1 = poison)`).

https://github.com/llvm/llvm-project/pull/109736


More information about the llvm-commits mailing list