[PATCH] D107254: [VectorUtils] Teach findScalarElement to return splat value.

Sander de Smalen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 15 04:21:40 PDT 2021


sdesmalen added inline comments.


================
Comment at: llvm/lib/Analysis/VectorUtils.cpp:329
+    if (Value *Splat = getSplatValue(V))
+      if (EltNo < VTy->getElementCount().getKnownMinValue())
+        return Splat;
----------------
spatel wrote:
> sdesmalen wrote:
> > @spatel, I wasn't entirely sure if similar arguments apply as mentioned here: https://reviews.llvm.org/D104867#2840537
> Oops - missed this comment. If it's a splat, then do we care what EltNo is?
> 
> Ie, if we have this:
> define i64 @ext_lane_from_splat(i64 %v) {
>   %in = insertelement <vscale x 4 x i64> poison, i64 %v, i32 0
>   %splat = shufflevector <vscale x 4 x i64> %in, <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
>   %r = extractelement <vscale x 4 x i64> %splat, i32 4 ; what does it mean if there are only 4 elts at runtime?
>   ret i64 %r
> }
> 
> Should it simplify to `ret i64 %v`?
The LangRef states that if there are only 4 elements at runtime, that extracting element 4 results in a poison value. I'm tempted to argue that if executed on a machine with a wider vector width, returning `%v` would be safe, so  we can equally assume returning `%v` should not lead to undefined behaviour on a machine that has shorter vectors. But my knowledge of poison is a bit lacking here, so I'm not sure if that assumption is safe to make.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107254



More information about the llvm-commits mailing list