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 @@ -1123,7 +1123,10 @@ // else. Only do this if CmpRHS is a constant, as profitability is not // clear for other cases. // FIXME: The replacement could be performed recursively. - if (isa(CmpRHS) && !isa(CmpRHS)) + auto IsConstant = [](auto *V) { + return isa(V) && !isa(V); + }; + if (IsConstant(CmpRHS) && !IsConstant(CmpLHS)) if (auto *I = dyn_cast(TrueVal)) if (I->hasOneUse()) for (Use &U : I->operands())