Index: lib/Transforms/Scalar/Reassociate.cpp =================================================================== --- lib/Transforms/Scalar/Reassociate.cpp +++ lib/Transforms/Scalar/Reassociate.cpp @@ -1520,8 +1520,8 @@ if (ConstantInt *CI = dyn_cast(Factor)) { if (CI->isNegative() && !CI->isMinValue(true)) { Factor = ConstantInt::get(CI->getContext(), -CI->getValue()); - assert(!Duplicates.count(Factor) && - "Shouldn't have two constant factors, missed a canonicalize"); + if (!Duplicates.insert(Factor).second) + continue; unsigned Occ = ++FactorOccurrences[Factor]; if (Occ > MaxOcc) { MaxOcc = Occ; @@ -1533,8 +1533,8 @@ APFloat F(CF->getValueAPF()); F.changeSign(); Factor = ConstantFP::get(CF->getContext(), F); - assert(!Duplicates.count(Factor) && - "Shouldn't have two constant factors, missed a canonicalize"); + if (!Duplicates.insert(Factor).second) + continue; unsigned Occ = ++FactorOccurrences[Factor]; if (Occ > MaxOcc) { MaxOcc = Occ; Index: test/Transforms/Reassociate/basictest.ll =================================================================== --- test/Transforms/Reassociate/basictest.ll +++ test/Transforms/Reassociate/basictest.ll @@ -222,3 +222,19 @@ ; CHECK-LABEL: @test15 ; CHECK: and i1 %A, %B } + +; PR30256 - Just make sure we don't hit an assert. +define i64 @test16(i1 %cmp, i64 %a, i64 %b) { +entry: + %shl = shl i64 %a, 1 + %shl.neg = sub i64 0, %shl + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry + %add1 = add i64 %shl.neg, %shl.neg + %add2 = add i64 %add1, %b + ret i64 %add2 + +if.end: ; preds = %entry + ret i64 0 +}