diff --git a/llvm/include/llvm/Analysis/InstructionSimplify.h b/llvm/include/llvm/Analysis/InstructionSimplify.h --- a/llvm/include/llvm/Analysis/InstructionSimplify.h +++ b/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 diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/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;