Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp =================================================================== --- llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -355,7 +355,8 @@ Value *Op1 = MatchIsOpZero ? NewSI : MatchOp; if (auto *BO = dyn_cast(TI)) { BinaryOperator *NewBO = BinaryOperator::Create(BO->getOpcode(), Op0, Op1); - NewBO->copyIRFlags(BO); + NewBO->copyIRFlags(TI); + NewBO->andIRFlags(FI); return NewBO; } if (auto *TGEP = dyn_cast(TI)) { Index: llvm/trunk/test/Transforms/InstCombine/select_meta.ll =================================================================== --- llvm/trunk/test/Transforms/InstCombine/select_meta.ll +++ llvm/trunk/test/Transforms/InstCombine/select_meta.ll @@ -7,12 +7,12 @@ ; CHECK-LABEL: @foo( ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 %0, 2 ; CHECK-NEXT: [[DOTV:%.*]] = select i1 [[TMP2]], i32 20, i32 -20, !prof ![[$MD1:[0-9]+]] -; CHECK-NEXT: [[TMP3:%.*]] = add nsw i32 [[DOTV]], %0 +; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[DOTV]], %0 ; CHECK-NEXT: ret i32 [[TMP3]] ; %2 = icmp sgt i32 %0, 2 %3 = add nsw i32 %0, 20 - %4 = add nsw i32 %0, -20 + %4 = add i32 %0, -20 select i1 %2, i32 %3, i32 %4, !prof !1 ret i32 %5 }