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 @@ -1141,6 +1141,7 @@ if (SPF == SelectPatternFlavor::SPF_NABS) return BinaryOperator::CreateNeg(Abs); // Always without NSW flag! + Abs->takeName(&Sel); return IC.replaceInstUsesWith(Sel, Abs); } @@ -1162,8 +1163,9 @@ default: llvm_unreachable("Unexpected SPF"); } - return IC.replaceInstUsesWith( - Sel, IC.Builder.CreateBinaryIntrinsic(IntrinsicID, LHS, RHS)); + Instruction *MinMax = IC.Builder.CreateBinaryIntrinsic(IntrinsicID, LHS, RHS); + MinMax->takeName(&Sel); + return IC.replaceInstUsesWith(Sel, MinMax); } return nullptr;