diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -390,7 +390,8 @@ // or i1 Op, SI / select i1 Op, i1 true, i1 SI (if IsAnd = false) // into simplier select instruction using isImpliedCondition. Instruction *foldAndOrOfSelectUsingImpliedCond(Value *Op, SelectInst &SI, - bool IsAnd); + bool IsAnd, + bool NotSICond = false); Instruction *hoistFNegAboveFMulFDiv(Value *FNegOp, Instruction &FMFSource); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -2643,9 +2643,8 @@ return nullptr; } -Instruction *InstCombinerImpl::foldAndOrOfSelectUsingImpliedCond(Value *Op, - SelectInst &SI, - bool IsAnd) { +Instruction *InstCombinerImpl::foldAndOrOfSelectUsingImpliedCond( + Value *Op, SelectInst &SI, bool IsAnd, bool NotSICond) { Value *CondVal = SI.getCondition(); Value *A = SI.getTrueValue(); Value *B = SI.getFalseValue(); @@ -2657,6 +2656,9 @@ if (!Res) return nullptr; + if (NotSICond) + *Res = !*Res; + Value *Zero = Constant::getNullValue(A->getType()); Value *One = Constant::getAllOnesValue(A->getType());