Index: lib/Transforms/InstCombine/InstructionCombining.cpp =================================================================== --- lib/Transforms/InstCombine/InstructionCombining.cpp +++ lib/Transforms/InstCombine/InstructionCombining.cpp @@ -3452,26 +3452,6 @@ } } - // In general, it is possible for computeKnownBits to determine all bits in - // a value even when the operands are not all constants. - Type *Ty = I->getType(); - if (ExpensiveCombines && !I->use_empty() && Ty->isIntOrIntVectorTy()) { - KnownBits Known = computeKnownBits(I, /*Depth*/0, I); - if (Known.isConstant()) { - Constant *C = ConstantInt::get(Ty, Known.getConstant()); - LLVM_DEBUG(dbgs() << "IC: ConstFold (all bits known) to: " << *C - << " from: " << *I << '\n'); - - // Add operands to the worklist. - replaceInstUsesWith(*I, C); - ++NumConstProp; - if (isInstructionTriviallyDead(I, &TLI)) - eraseInstFromFunction(*I); - MadeIRChange = true; - continue; - } - } - // See if we can trivially sink this instruction to a successor basic block. if (EnableCodeSinking && I->hasOneUse()) { BasicBlock *BB = I->getParent(); Index: test/Transforms/InstCombine/all-bits-shift.ll =================================================================== --- test/Transforms/InstCombine/all-bits-shift.ll +++ test/Transforms/InstCombine/all-bits-shift.ll @@ -13,33 +13,27 @@ ; ((2072 >> (L == 0)) >> 7) & 1 ; is always zero. define signext i32 @main() #1 { -; EXPENSIVE-OFF-LABEL: @main( -; EXPENSIVE-OFF-NEXT: entry: -; EXPENSIVE-OFF-NEXT: [[TMP0:%.*]] = load i32*, i32** @b, align 8 -; EXPENSIVE-OFF-NEXT: [[TMP1:%.*]] = load i32, i32* @a, align 4 -; EXPENSIVE-OFF-NEXT: [[LNOT:%.*]] = icmp eq i32 [[TMP1]], 0 -; EXPENSIVE-OFF-NEXT: [[LNOT_EXT:%.*]] = zext i1 [[LNOT]] to i32 -; EXPENSIVE-OFF-NEXT: [[SHR_I:%.*]] = lshr i32 2072, [[LNOT_EXT]] -; EXPENSIVE-OFF-NEXT: [[CALL_LOBIT:%.*]] = lshr i32 [[SHR_I]], 7 -; EXPENSIVE-OFF-NEXT: [[TMP2:%.*]] = and i32 [[CALL_LOBIT]], 1 -; EXPENSIVE-OFF-NEXT: [[TMP3:%.*]] = load i32, i32* [[TMP0]], align 4 -; EXPENSIVE-OFF-NEXT: [[OR:%.*]] = or i32 [[TMP2]], [[TMP3]] -; EXPENSIVE-OFF-NEXT: store i32 [[OR]], i32* [[TMP0]], align 4 -; EXPENSIVE-OFF-NEXT: [[TMP4:%.*]] = load i32, i32* @a, align 4 -; EXPENSIVE-OFF-NEXT: [[LNOT_1:%.*]] = icmp eq i32 [[TMP4]], 0 -; EXPENSIVE-OFF-NEXT: [[LNOT_EXT_1:%.*]] = zext i1 [[LNOT_1]] to i32 -; EXPENSIVE-OFF-NEXT: [[SHR_I_1:%.*]] = lshr i32 2072, [[LNOT_EXT_1]] -; EXPENSIVE-OFF-NEXT: [[CALL_LOBIT_1:%.*]] = lshr i32 [[SHR_I_1]], 7 -; EXPENSIVE-OFF-NEXT: [[TMP5:%.*]] = and i32 [[CALL_LOBIT_1]], 1 -; EXPENSIVE-OFF-NEXT: [[OR_1:%.*]] = or i32 [[TMP5]], [[TMP3]] -; EXPENSIVE-OFF-NEXT: store i32 [[OR_1]], i32* [[TMP0]], align 4 -; EXPENSIVE-OFF-NEXT: ret i32 [[OR_1]] -; -; EXPENSIVE-ON-LABEL: @main( -; EXPENSIVE-ON-NEXT: entry: -; EXPENSIVE-ON-NEXT: [[TMP0:%.*]] = load i32*, i32** @b, align 8 -; EXPENSIVE-ON-NEXT: [[TMP1:%.*]] = load i32, i32* [[TMP0]], align 4 -; EXPENSIVE-ON-NEXT: ret i32 [[TMP1]] +; CHECK-LABEL: @main( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[TMP0:%.*]] = load i32*, i32** @b, align 8 +; CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* @a, align 4 +; CHECK-NEXT: [[LNOT:%.*]] = icmp eq i32 [[TMP1]], 0 +; CHECK-NEXT: [[LNOT_EXT:%.*]] = zext i1 [[LNOT]] to i32 +; CHECK-NEXT: [[SHR_I:%.*]] = lshr i32 2072, [[LNOT_EXT]] +; CHECK-NEXT: [[CALL_LOBIT:%.*]] = lshr i32 [[SHR_I]], 7 +; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[CALL_LOBIT]], 1 +; CHECK-NEXT: [[TMP3:%.*]] = load i32, i32* [[TMP0]], align 4 +; CHECK-NEXT: [[OR:%.*]] = or i32 [[TMP2]], [[TMP3]] +; CHECK-NEXT: store i32 [[OR]], i32* [[TMP0]], align 4 +; CHECK-NEXT: [[TMP4:%.*]] = load i32, i32* @a, align 4 +; CHECK-NEXT: [[LNOT_1:%.*]] = icmp eq i32 [[TMP4]], 0 +; CHECK-NEXT: [[LNOT_EXT_1:%.*]] = zext i1 [[LNOT_1]] to i32 +; CHECK-NEXT: [[SHR_I_1:%.*]] = lshr i32 2072, [[LNOT_EXT_1]] +; CHECK-NEXT: [[CALL_LOBIT_1:%.*]] = lshr i32 [[SHR_I_1]], 7 +; CHECK-NEXT: [[TMP5:%.*]] = and i32 [[CALL_LOBIT_1]], 1 +; CHECK-NEXT: [[OR_1:%.*]] = or i32 [[TMP5]], [[TMP3]] +; CHECK-NEXT: store i32 [[OR_1]], i32* [[TMP0]], align 4 +; CHECK-NEXT: ret i32 [[OR_1]] ; entry: %0 = load i32*, i32** @b, align 8 Index: test/Transforms/InstCombine/assume.ll =================================================================== --- test/Transforms/InstCombine/assume.ll +++ test/Transforms/InstCombine/assume.ll @@ -332,16 +332,12 @@ ; PR35846 - https://bugs.llvm.org/show_bug.cgi?id=35846 define i32 @assumption_conflicts_with_known_bits(i32 %a, i32 %b) { -; EXPENSIVE-ON-LABEL: @assumption_conflicts_with_known_bits( -; EXPENSIVE-ON-NEXT: tail call void @llvm.assume(i1 false) -; EXPENSIVE-ON-NEXT: ret i32 0 -; -; EXPENSIVE-OFF-LABEL: @assumption_conflicts_with_known_bits( -; EXPENSIVE-OFF-NEXT: [[AND1:%.*]] = and i32 [[B:%.*]], 3 -; EXPENSIVE-OFF-NEXT: tail call void @llvm.assume(i1 false) -; EXPENSIVE-OFF-NEXT: [[CMP2:%.*]] = icmp eq i32 [[AND1]], 0 -; EXPENSIVE-OFF-NEXT: tail call void @llvm.assume(i1 [[CMP2]]) -; EXPENSIVE-OFF-NEXT: ret i32 0 +; CHECK-LABEL: @assumption_conflicts_with_known_bits( +; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B:%.*]], 3 +; CHECK-NEXT: tail call void @llvm.assume(i1 false) +; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[AND1]], 0 +; CHECK-NEXT: tail call void @llvm.assume(i1 [[CMP2]]) +; CHECK-NEXT: ret i32 0 ; %and1 = and i32 %b, 3 %B1 = lshr i32 %and1, %and1 Index: test/Transforms/InstCombine/expensive-combines.ll =================================================================== --- test/Transforms/InstCombine/expensive-combines.ll +++ test/Transforms/InstCombine/expensive-combines.ll @@ -6,12 +6,12 @@ define void @test() { ; DEFAULT-LABEL: @test( ; DEFAULT-NEXT: [[CALL:%.*]] = call i32 @passthru(i32 0) -; DEFAULT-NEXT: call void @sink(i32 0) +; DEFAULT-NEXT: call void @sink(i32 [[CALL]]) ; DEFAULT-NEXT: ret void ; ; EXPENSIVE-ON-LABEL: @test( ; EXPENSIVE-ON-NEXT: [[CALL:%.*]] = call i32 @passthru(i32 0) -; EXPENSIVE-ON-NEXT: call void @sink(i32 0) +; EXPENSIVE-ON-NEXT: call void @sink(i32 [[CALL]]) ; EXPENSIVE-ON-NEXT: ret void ; ; EXPENSIVE-OFF-LABEL: @test( Index: test/Transforms/InstCombine/out-of-bounds-indexes.ll =================================================================== --- test/Transforms/InstCombine/out-of-bounds-indexes.ll +++ test/Transforms/InstCombine/out-of-bounds-indexes.ll @@ -4,17 +4,11 @@ ; Check that we don't crash on unreasonable constant indexes define i32 @test_out_of_bounds(i32 %a, i1 %x, i1 %y) { -; EXPENSIVE-OFF-LABEL: @test_out_of_bounds( -; EXPENSIVE-OFF-NEXT: entry: -; EXPENSIVE-OFF-NEXT: [[AND1:%.*]] = and i32 [[A:%.*]], 3 -; EXPENSIVE-OFF-NEXT: tail call void @llvm.assume(i1 undef) -; EXPENSIVE-OFF-NEXT: ret i32 [[AND1]] -; -; EXPENSIVE-ON-LABEL: @test_out_of_bounds( -; EXPENSIVE-ON-NEXT: entry: -; EXPENSIVE-ON-NEXT: [[AND1:%.*]] = and i32 [[A:%.*]], 3 -; EXPENSIVE-ON-NEXT: tail call void @llvm.assume(i1 false) -; EXPENSIVE-ON-NEXT: ret i32 [[AND1]] +; CHECK-LABEL: @test_out_of_bounds( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[AND1:%.*]] = and i32 [[A:%.*]], 3 +; CHECK-NEXT: tail call void @llvm.assume(i1 undef) +; CHECK-NEXT: ret i32 [[AND1]] ; entry: %and1 = and i32 %a, 3 @@ -25,15 +19,10 @@ } define i128 @test_non64bit(i128 %a) { -; EXPENSIVE-OFF-LABEL: @test_non64bit( -; EXPENSIVE-OFF-NEXT: [[AND1:%.*]] = and i128 [[A:%.*]], 3 -; EXPENSIVE-OFF-NEXT: tail call void @llvm.assume(i1 undef) -; EXPENSIVE-OFF-NEXT: ret i128 [[AND1]] -; -; EXPENSIVE-ON-LABEL: @test_non64bit( -; EXPENSIVE-ON-NEXT: [[AND1:%.*]] = and i128 [[A:%.*]], 3 -; EXPENSIVE-ON-NEXT: tail call void @llvm.assume(i1 false) -; EXPENSIVE-ON-NEXT: ret i128 [[AND1]] +; CHECK-LABEL: @test_non64bit( +; CHECK-NEXT: [[AND1:%.*]] = and i128 [[A:%.*]], 3 +; CHECK-NEXT: tail call void @llvm.assume(i1 undef) +; CHECK-NEXT: ret i128 [[AND1]] ; %and1 = and i128 %a, 3 %B = lshr i128 %and1, -1 Index: test/Transforms/InstCombine/phi-shifts.ll =================================================================== --- test/Transforms/InstCombine/phi-shifts.ll +++ test/Transforms/InstCombine/phi-shifts.ll @@ -4,21 +4,13 @@ ; OSS Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=15217 define i64 @fuzz15217(i1 %cond, i8* %Ptr, i64 %Val) { -; EXPENSIVE-OFF-LABEL: @fuzz15217( -; EXPENSIVE-OFF-NEXT: entry: -; EXPENSIVE-OFF-NEXT: br i1 [[COND:%.*]], label [[END:%.*]], label [[TWO:%.*]] -; EXPENSIVE-OFF: two: -; EXPENSIVE-OFF-NEXT: br label [[END]] -; EXPENSIVE-OFF: end: -; EXPENSIVE-OFF-NEXT: ret i64 undef -; -; EXPENSIVE-ON-LABEL: @fuzz15217( -; EXPENSIVE-ON-NEXT: entry: -; EXPENSIVE-ON-NEXT: br i1 [[COND:%.*]], label [[END:%.*]], label [[TWO:%.*]] -; EXPENSIVE-ON: two: -; EXPENSIVE-ON-NEXT: br label [[END]] -; EXPENSIVE-ON: end: -; EXPENSIVE-ON-NEXT: ret i64 0 +; CHECK-LABEL: @fuzz15217( +; CHECK-NEXT: entry: +; CHECK-NEXT: br i1 [[COND:%.*]], label [[END:%.*]], label [[TWO:%.*]] +; CHECK: two: +; CHECK-NEXT: br label [[END]] +; CHECK: end: +; CHECK-NEXT: ret i64 undef ; entry: br i1 %cond, label %end, label %two