[PATCH] D85684: [InstSimplify] Forbid undef folds in expandBinOp

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 13:23:13 PDT 2020


nikic created this revision.
nikic added reviewers: spatel, aqjune, craig.topper, lebedev.ri, fhahn.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
nikic requested review of this revision.

This is the replacement for D84250 <https://reviews.llvm.org/D84250> based on D84792 <https://reviews.llvm.org/D84792>. As we recursively fold with the same value twice, we need to disable undef folds, to prevent an undef from being folded to two different values.

Reverting the revert rG00f3579aea6e3d4a4b7464c3db47294f71cef9e4 <https://reviews.llvm.org/rG00f3579aea6e3d4a4b7464c3db47294f71cef9e4> and using the test case from https://reviews.llvm.org/D83360#2145793, it no longer performs the incorrect fold.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85684

Files:
  llvm/include/llvm/Analysis/InstructionSimplify.h
  llvm/lib/Analysis/InstructionSimplify.cpp


Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -238,10 +238,12 @@
   if (!B || B->getOpcode() != OpcodeToExpand)
     return nullptr;
   Value *B0 = B->getOperand(0), *B1 = B->getOperand(1);
-  Value *L = SimplifyBinOp(Opcode, B0, OtherOp, Q, MaxRecurse);
+  Value *L = SimplifyBinOp(Opcode, B0, OtherOp, Q.getWithoutUndef(),
+                           MaxRecurse);
   if (!L)
     return nullptr;
-  Value *R = SimplifyBinOp(Opcode, B1, OtherOp, Q, MaxRecurse);
+  Value *R = SimplifyBinOp(Opcode, B1, OtherOp, Q.getWithoutUndef(),
+                           MaxRecurse);
   if (!R)
     return nullptr;
 
Index: llvm/include/llvm/Analysis/InstructionSimplify.h
===================================================================
--- llvm/include/llvm/Analysis/InstructionSimplify.h
+++ llvm/include/llvm/Analysis/InstructionSimplify.h
@@ -118,6 +118,11 @@
     Copy.CxtI = I;
     return Copy;
   }
+  SimplifyQuery getWithoutUndef() const {
+    SimplifyQuery Copy(*this);
+    Copy.CanUseUndef = false;
+    return Copy;
+  }
 };
 
 // NOTE: the explicit multiple argument versions of these functions are


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85684.284489.patch
Type: text/x-patch
Size: 1276 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200810/cda3a268/attachment.bin>


More information about the llvm-commits mailing list