[llvm] d110d4a - [InstSimplify] Forbid undef folds in expandBinOp

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 09:39:33 PDT 2020


Author: Nikita Popov
Date: 2020-08-11T18:39:24+02:00
New Revision: d110d4aaff31198cd455b68617978019a8339773

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

LOG: [InstSimplify] Forbid undef folds in expandBinOp

This is the replacement for D84250 based on 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 rG00f3579aea6e3d4a4b7464c3db47294f71cef9e4 and using the
test case from https://reviews.llvm.org/D83360#2145793, it no longer
performs the incorrect fold.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/InstructionSimplify.h b/llvm/include/llvm/Analysis/InstructionSimplify.h
index 06dc195979c9..640e1fda2119 100644
--- a/llvm/include/llvm/Analysis/InstructionSimplify.h
+++ b/llvm/include/llvm/Analysis/InstructionSimplify.h
@@ -118,6 +118,11 @@ struct SimplifyQuery {
     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

diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 20d0184a718f..893de596e1a7 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -238,10 +238,12 @@ static Value *expandBinOp(Instruction::BinaryOps Opcode, Value *V,
   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;
 


        


More information about the llvm-commits mailing list