[PATCH] D98410: [ConstantFold] Handle undef/poison when constant folding smul_fix/smul_fix_sat

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 11 07:59:16 PST 2021


aqjune added inline comments.


================
Comment at: llvm/test/Transforms/InstSimplify/ConstProp/smul-fix.ll:148
+  <8 x i3> <i3 undef, i3 2, i3 poison, i3 2, i3 2, i3 2, i3 2, i3 2>,
+  i32 2)
+  ret <8 x i3> %r
----------------
aqjune wrote:
> I found from LangRef that actually this can be optimized further:
> ```
> It is undefined behavior if the result value does not fit within the range of the fixed point type.
> ```
> 
> The result of the third element, `llvm.smul.fix.v8i3(2, poison, 2)`, raises UB because `poison` can be folded into a large number which explicitly leads to UB.
> Then, output elements not only 3rd/4th but also others are okay to be folded to `poison`.
> 
> `udiv <x, x>, <0, 1>` is also returning `<undef, undef>` in the same context currently.
> 
> Would this optimization be necessary though? 
> The result of the third element, llvm.smul.fix.v8i3(2, poison, 2), raises UB because poison can be folded into a large number which explicitly leads to UB.

Nevermind, I forgot the scale thing.
The first argument is actually 0.5 and the second one is, well, poison / 4, so it is UB if "0.5 * (poison / 4)" can overflow. Is my understanding right?
Then, I think it is uncertain whether this is UB or not.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98410/new/

https://reviews.llvm.org/D98410



More information about the llvm-commits mailing list