Index: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp +++ llvm/trunk/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: llvm/trunk/test/Transforms/Reassociate/basictest.ll =================================================================== --- llvm/trunk/test/Transforms/Reassociate/basictest.ll +++ llvm/trunk/test/Transforms/Reassociate/basictest.ll @@ -222,3 +222,23 @@ ; CHECK-LABEL: @test15 ; CHECK: and i1 %A, %B } + +; PR30256 - previously this asserted. +; CHECK-LABEL: @test16 +; CHECK: %[[FACTOR:.*]] = mul i64 %a, -4 +; CHECK-NEXT: %[[RES:.*]] = add i64 %[[FACTOR]], %b +; CHECK-NEXT: ret i64 %[[RES]] +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 +}