[PATCH] D40231: InstructionSimplify: 'extractelement' with an undef index is undef

Zvi Rackover via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 19 15:01:21 PST 2017


zvi created this revision.
Herald added a subscriber: wdng.

An undef extract index can be arbitrarily chosen to be an
out-of-range index value, which would result in the instruction being undef.

This change closes a gap identified while working on lowering vector permute intrinsics
with variable index vectors to pure LLVM IR.


https://reviews.llvm.org/D40231

Files:
  lib/Analysis/InstructionSimplify.cpp
  test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll


Index: test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
===================================================================
--- test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
+++ test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
@@ -46,3 +46,10 @@
 ; CHECK-NEXT: %[[extract:.*]] = extractelement <8 x i8> %[[add]], i32 6
 ; CHECK-NEXT: ret i8 %[[extract]]
 }
+
+define i32 @test5(<4 x i32> %V) {
+  %extract = extractelement <4 x i32> %V, i32 undef
+  ret i32 %extract
+}
+; CHECK-LABEL: @test5(
+; CHECK: ret i32 undef
Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -3863,6 +3863,11 @@
     if (Value *Elt = findScalarElement(Vec, IdxC->getZExtValue()))
       return Elt;
 
+  // An undef extract index can be arbitrarily chosen to be an out-of-range
+  // index value, which would result in the instruction being undef.
+  if (isa<UndefValue>(Idx))
+    return UndefValue::get(Vec->getType()->getVectorElementType());
+
   return nullptr;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40231.123519.patch
Type: text/x-patch
Size: 1137 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171119/10418fad/attachment.bin>


More information about the llvm-commits mailing list