From d110d4aaff31198cd455b68617978019a8339773 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 10 Aug 2020 22:06:48 +0200 Subject: [PATCH] [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 --- llvm/include/llvm/Analysis/InstructionSimplify.h | 5 +++++ llvm/lib/Analysis/InstructionSimplify.cpp | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/Analysis/InstructionSimplify.h b/llvm/include/llvm/Analysis/InstructionSimplify.h index 06dc195..640e1fd 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 20d0184..893de59 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; -- 2.7.4