[PATCH] D83442: [InstSimplify] Don't fold vectors of partial undef in SimplifySelectInst if the non-undef element value might produce poison

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 9 11:01:45 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG122b0640fc97: [InstSimplify] Don't fold vectors of partial undef in SimplifySelectInst if theā€¦ (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83442

Files:
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/test/Transforms/InstSimplify/select.ll


Index: llvm/test/Transforms/InstSimplify/select.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/select.ll
+++ llvm/test/Transforms/InstSimplify/select.ll
@@ -848,3 +848,17 @@
   %s = select i1 %cond, i32 undef, i32 %xf
   ret i32 %s
 }
+
+ at g = external global i32, align 1
+
+; Make sure we don't fold partial undef vectors when constexprs are involved.
+; We would need to prove the constexpr doesn't result in poison which we aren't
+; equiped to do yet.
+define <2 x i32> @false_undef_true_constextpr_vec(i1 %cond) {
+; CHECK-LABEL: @false_undef_true_constextpr_vec(
+; CHECK-NEXT:    [[S:%.*]] = select i1 [[COND:%.*]], <2 x i32> <i32 undef, i32 ptrtoint (i32* @g to i32)>, <2 x i32> <i32 ptrtoint (i32* @g to i32), i32 undef>
+; CHECK-NEXT:    ret <2 x i32> [[S]]
+;
+  %s = select i1 %cond, <2 x i32> <i32 undef, i32 ptrtoint (i32* @g to i32)>, <2 x i32> <i32 ptrtoint (i32* @g to i32), i32 undef>
+  ret <2 x i32> %s
+}
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4135,9 +4135,11 @@
       // one element is undef, choose the defined element as the safe result.
       if (TEltC == FEltC)
         NewC.push_back(TEltC);
-      else if (isa<UndefValue>(TEltC))
+      else if (isa<UndefValue>(TEltC) &&
+               isGuaranteedNotToBeUndefOrPoison(FEltC))
         NewC.push_back(FEltC);
-      else if (isa<UndefValue>(FEltC))
+      else if (isa<UndefValue>(FEltC) &&
+               isGuaranteedNotToBeUndefOrPoison(TEltC))
         NewC.push_back(TEltC);
       else
         break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83442.276781.patch
Type: text/x-patch
Size: 1728 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200709/fb80f3af/attachment.bin>


More information about the llvm-commits mailing list