[llvm-branch-commits] [llvm] f665a8c - [InstSimplify] gep with poison operand is poison

Juneyoung Lee via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Jan 4 18:13:34 PST 2021


Author: Juneyoung Lee
Date: 2021-01-05T11:07:49+09:00
New Revision: f665a8c5b8b42d88f89e1a3594b7d410ef206c32

URL: https://github.com/llvm/llvm-project/commit/f665a8c5b8b42d88f89e1a3594b7d410ef206c32
DIFF: https://github.com/llvm/llvm-project/commit/f665a8c5b8b42d88f89e1a3594b7d410ef206c32.diff

LOG: [InstSimplify] gep with poison operand is poison

This is a tiny update to fold gep poison into poison. :)

Alive2 proofs:
https://alive2.llvm.org/ce/z/7Nwdri
https://alive2.llvm.org/ce/z/sDP4sC

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/InstSimplify/gep.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index dfaf36a96953..659b71fae6a0 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4242,6 +4242,11 @@ static Value *SimplifyGEPInst(Type *SrcTy, ArrayRef<Value *> Ops,
   else if (VectorType *VT = dyn_cast<VectorType>(Ops[1]->getType()))
     GEPTy = VectorType::get(GEPTy, VT->getElementCount());
 
+  // getelementptr poison, idx -> poison
+  // getelementptr baseptr, poison -> poison
+  if (any_of(Ops, [](const auto *V) { return isa<PoisonValue>(V); }))
+    return PoisonValue::get(GEPTy);
+
   if (Q.isUndefValue(Ops[0]))
     return UndefValue::get(GEPTy);
 

diff  --git a/llvm/test/Transforms/InstSimplify/gep.ll b/llvm/test/Transforms/InstSimplify/gep.ll
index 804ce7f10a8c..e6670e4a9345 100644
--- a/llvm/test/Transforms/InstSimplify/gep.ll
+++ b/llvm/test/Transforms/InstSimplify/gep.ll
@@ -222,7 +222,7 @@ define <vscale x 2 x i64*> @ptr_idx_mix_scalar_scalable_vector() {
 
 define i8* @poison() {
 ; CHECK-LABEL: @poison(
-; CHECK-NEXT:    ret i8* undef
+; CHECK-NEXT:    ret i8* poison
 ;
   %v = getelementptr i8, i8* poison, i64 1
   ret i8* %v
@@ -230,8 +230,7 @@ define i8* @poison() {
 
 define i8* @poison2(i8* %baseptr) {
 ; CHECK-LABEL: @poison2(
-; CHECK-NEXT:    [[V:%.*]] = getelementptr i8, i8* [[BASEPTR:%.*]], i64 poison
-; CHECK-NEXT:    ret i8* [[V]]
+; CHECK-NEXT:    ret i8* poison
 ;
   %v = getelementptr i8, i8* %baseptr, i64 poison
   ret i8* %v


        


More information about the llvm-branch-commits mailing list