[PATCH] D92203: [ConstantFold] Fold operations to poison if possible

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 27 05:44:53 PST 2020

aqjune added inline comments.

Comment at: llvm/lib/IR/ConstantFold.cpp:841
+  // extractelt poison, C -> poison
+  // extractelt C, undef -> poison
+  if (isa<PoisonValue>(Val) || isa<UndefValue>(Idx))
aqjune wrote:
> This is poison because undef can be folded into out-of-bounds index, which makes extractelement yield poison according to LangRef.
(I see that this is slightly different from shufflevector, which states that undef mask blocks poison.
In the case of shufflevector, the mask should be either undef or integer constant: undef rather works as a special value stating the result should be undef.
But, insertelement can accept variable index. An undef value at the index can be folded to any value, including out-of-bounds.
This is my understanding, and if this seems okay, I'll make a separate LangRef patch that explicitly says insertelement with undef index is poison (and extractelement as well).

  rG LLVM Github Monorepo



More information about the llvm-commits mailing list