[llvm] r319910 - InstructionSimplify: 'extractelement' with an undef index is undef

Zvi Rackover via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 6 09:51:46 PST 2017


Author: zvi
Date: Wed Dec  6 09:51:46 2017
New Revision: 319910

URL: http://llvm.org/viewvc/llvm-project?rev=319910&view=rev
Log:
InstructionSimplify: 'extractelement' with an undef index is undef

Summary:
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.

Reviewers: arsenm, spatel, majnemer

Reviewed By: arsenm, spatel

Subscribers: fhahn, nhaehnle, wdng, llvm-commits

Differential Revision: https://reviews.llvm.org/D40231

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

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=319910&r1=319909&r2=319910&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Wed Dec  6 09:51:46 2017
@@ -3901,6 +3901,11 @@ static Value *SimplifyExtractElementInst
     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;
 }
 

Modified: llvm/trunk/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll?rev=319910&r1=319909&r2=319910&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll Wed Dec  6 09:51:46 2017
@@ -46,3 +46,10 @@ define i8 @test4(<8 x i8> %V) {
 ; 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




More information about the llvm-commits mailing list