Index: lib/Analysis/InstructionSimplify.cpp =================================================================== --- lib/Analysis/InstructionSimplify.cpp +++ lib/Analysis/InstructionSimplify.cpp @@ -5600,9 +5600,6 @@ break; case Instruction::Call: { Result = SimplifyCall(cast(I), Q); - // Don't perform known bits simplification below for musttail calls. - if (cast(I)->isMustTailCall()) - return Result; break; } case Instruction::Freeze: @@ -5620,14 +5617,6 @@ break; } - // In general, it is possible for computeKnownBits to determine all bits in a - // value even when the operands are not all constants. - if (!Result && I->getType()->isIntOrIntVectorTy()) { - KnownBits Known = computeKnownBits(I, Q.DL, /*Depth*/ 0, Q.AC, I, Q.DT, ORE); - if (Known.isConstant()) - Result = ConstantInt::get(I->getType(), Known.getConstant()); - } - /// If called on unreachable code, the above logic may report that the /// instruction simplified to itself. Make life easier for users by /// detecting that case here, returning a safe value instead. Index: test/Analysis/ValueTracking/knownnonzero-shift.ll =================================================================== --- test/Analysis/ValueTracking/knownnonzero-shift.ll +++ test/Analysis/ValueTracking/knownnonzero-shift.ll @@ -3,7 +3,11 @@ define i1 @test(i8 %p, i8* %pq) { ; CHECK-LABEL: @test( -; CHECK-NEXT: ret i1 true +; CHECK-NEXT: [[Q:%.*]] = load i8, i8* [[PQ:%.*]], !range !0 +; CHECK-NEXT: [[TMP1:%.*]] = shl i8 [[P:%.*]], [[Q]] +; CHECK-NEXT: [[TMP2:%.*]] = and i8 [[TMP1]], 1 +; CHECK-NEXT: [[X:%.*]] = icmp eq i8 [[TMP2]], 0 +; CHECK-NEXT: ret i1 [[X]] ; %q = load i8, i8* %pq, !range !0 ; %q is known nonzero; no known bits %1 = shl i8 %p, %q ; because %q is nonzero, %1[0] is known to be zero. Index: test/Analysis/ValueTracking/knownzero-shift.ll =================================================================== --- test/Analysis/ValueTracking/knownzero-shift.ll +++ test/Analysis/ValueTracking/knownzero-shift.ll @@ -17,7 +17,9 @@ define i32 @shl_shl(i32 %A) { ; CHECK-LABEL: @shl_shl( -; CHECK-NEXT: ret i32 0 +; CHECK-NEXT: [[B:%.*]] = shl i32 [[A:%.*]], 6 +; CHECK-NEXT: [[C:%.*]] = shl i32 [[B]], 28 +; CHECK-NEXT: ret i32 [[C]] ; %B = shl i32 %A, 6 %C = shl i32 %B, 28 @@ -26,7 +28,9 @@ define <2 x i33> @shl_shl_splat_vec(<2 x i33> %A) { ; CHECK-LABEL: @shl_shl_splat_vec( -; CHECK-NEXT: ret <2 x i33> zeroinitializer +; CHECK-NEXT: [[B:%.*]] = shl <2 x i33> [[A:%.*]], +; CHECK-NEXT: [[C:%.*]] = shl <2 x i33> [[B]], +; CHECK-NEXT: ret <2 x i33> [[C]] ; %B = shl <2 x i33> %A, %C = shl <2 x i33> %B, @@ -37,7 +41,7 @@ define <2 x i33> @shl_shl_vec(<2 x i33> %A) { ; CHECK-LABEL: @shl_shl_vec( -; CHECK-NEXT: [[B:%.*]] = shl <2 x i33> %A, +; CHECK-NEXT: [[B:%.*]] = shl <2 x i33> [[A:%.*]], ; CHECK-NEXT: [[C:%.*]] = shl <2 x i33> [[B]], ; CHECK-NEXT: ret <2 x i33> [[C]] ; @@ -48,7 +52,9 @@ define i232 @lshr_lshr(i232 %A) { ; CHECK-LABEL: @lshr_lshr( -; CHECK-NEXT: ret i232 0 +; CHECK-NEXT: [[B:%.*]] = lshr i232 [[A:%.*]], 231 +; CHECK-NEXT: [[C:%.*]] = lshr i232 [[B]], 1 +; CHECK-NEXT: ret i232 [[C]] ; %B = lshr i232 %A, 231 %C = lshr i232 %B, 1 @@ -57,7 +63,9 @@ define <2 x i32> @lshr_lshr_splat_vec(<2 x i32> %A) { ; CHECK-LABEL: @lshr_lshr_splat_vec( -; CHECK-NEXT: ret <2 x i32> zeroinitializer +; CHECK-NEXT: [[B:%.*]] = lshr <2 x i32> [[A:%.*]], +; CHECK-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], +; CHECK-NEXT: ret <2 x i32> [[C]] ; %B = lshr <2 x i32> %A, %C = lshr <2 x i32> %B, @@ -66,7 +74,9 @@ define <2 x i32> @lshr_lshr_vec(<2 x i32> %A) { ; CHECK-LABEL: @lshr_lshr_vec( -; CHECK-NEXT: ret <2 x i32> zeroinitializer +; CHECK-NEXT: [[B:%.*]] = lshr <2 x i32> [[A:%.*]], +; CHECK-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], +; CHECK-NEXT: ret <2 x i32> [[C]] ; %B = lshr <2 x i32> %A, %C = lshr <2 x i32> %B, Index: test/Transforms/GVN/PRE/volatile.ll =================================================================== --- test/Transforms/GVN/PRE/volatile.ll +++ test/Transforms/GVN/PRE/volatile.ll @@ -201,7 +201,7 @@ ; CHECK-LABEL: @test9( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[LOAD:%.*]] = load volatile i32, i32* [[V:%.*]], !range !0 -; CHECK-NEXT: ret i32 0 +; CHECK-NEXT: ret i32 [[LOAD]] ; entry: %load = load volatile i32, i32* %V, !range !0 Index: test/Transforms/InstSimplify/assume.ll =================================================================== --- test/Transforms/InstSimplify/assume.ll +++ test/Transforms/InstSimplify/assume.ll @@ -1,11 +1,5 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt -instsimplify -S < %s 2>&1 -pass-remarks-analysis=.* | FileCheck %s - -; Verify that warnings are emitted for the 2nd and 3rd tests. - -; CHECK: remark: /tmp/s.c:1:13: Detected conflicting code assumptions. -; CHECK: remark: /tmp/s.c:4:10: Detected conflicting code assumptions. -; CHECK: remark: /tmp/s.c:5:50: Detected conflicting code assumptions. +; RUN: opt -instsimplify -S < %s 2>&1 | FileCheck %s define void @test1() { ; CHECK-LABEL: @test1( @@ -13,7 +7,6 @@ ; call void @llvm.assume(i1 1) ret void - } ; The alloca guarantees that the low bits of %a are zero because of alignment. @@ -23,7 +16,10 @@ define i64 @PR31809() !dbg !7 { ; CHECK-LABEL: @PR31809( -; CHECK-NEXT: ret i64 3 +; CHECK-NEXT: [[A:%.*]] = alloca i32 +; CHECK-NEXT: [[T1:%.*]] = ptrtoint i32* [[A]] to i64, !dbg !9 +; CHECK-NEXT: call void @llvm.assume(i1 false) +; CHECK-NEXT: ret i64 [[T1]] ; %a = alloca i32 %t1 = ptrtoint i32* %a to i64, !dbg !9 @@ -37,7 +33,7 @@ define i8 @conflicting_assumptions(i8 %x) !dbg !10 { ; CHECK-LABEL: @conflicting_assumptions( -; CHECK-NEXT: [[ADD:%.*]] = add i8 [[X:%.*]], 1, !dbg !10 +; CHECK-NEXT: [[ADD:%.*]] = add i8 [[X:%.*]], 1, !dbg !11 ; CHECK-NEXT: call void @llvm.assume(i1 false) ; CHECK-NEXT: [[COND2:%.*]] = icmp eq i8 [[X]], 4 ; CHECK-NEXT: call void @llvm.assume(i1 [[COND2]]) @@ -56,6 +52,10 @@ define void @PR36270(i32 %b) !dbg !13 { ; CHECK-LABEL: @PR36270( +; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B:%.*]], 3 +; CHECK-NEXT: [[B12:%.*]] = lshr i32 -2147483648, [[AND1]], !dbg !13 +; CHECK-NEXT: [[C1:%.*]] = icmp ult i32 [[AND1]], [[B12]] +; CHECK-NEXT: tail call void @llvm.assume(i1 [[C1]]) ; CHECK-NEXT: tail call void @llvm.assume(i1 false) ; CHECK-NEXT: unreachable ; Index: test/Transforms/InstSimplify/call.ll =================================================================== --- test/Transforms/InstSimplify/call.ll +++ test/Transforms/InstSimplify/call.ll @@ -988,7 +988,7 @@ define i32 @returned_const_int_arg() { ; CHECK-LABEL: @returned_const_int_arg( ; CHECK-NEXT: [[X:%.*]] = call i32 @passthru_i32(i32 42) -; CHECK-NEXT: ret i32 42 +; CHECK-NEXT: ret i32 [[X]] ; %x = call i32 @passthru_i32(i32 42) ret i32 %x Index: test/Transforms/InstSimplify/or.ll =================================================================== --- test/Transforms/InstSimplify/or.ll +++ test/Transforms/InstSimplify/or.ll @@ -101,7 +101,11 @@ ; (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2) define i8 @test11(i8 %A) { ; CHECK-LABEL: @test11( -; CHECK-NEXT: ret i8 -1 +; CHECK-NEXT: [[B:%.*]] = or i8 [[A:%.*]], -2 +; CHECK-NEXT: [[C:%.*]] = xor i8 [[B]], 13 +; CHECK-NEXT: [[D:%.*]] = or i8 [[C]], 1 +; CHECK-NEXT: [[E:%.*]] = xor i8 [[D]], 12 +; CHECK-NEXT: ret i8 [[E]] ; %B = or i8 %A, -2 %C = xor i8 %B, 13 @@ -112,7 +116,12 @@ define i8 @test11v(<2 x i8> %A) { ; CHECK-LABEL: @test11v( -; CHECK-NEXT: ret i8 -1 +; CHECK-NEXT: [[B:%.*]] = or <2 x i8> [[A:%.*]], +; CHECK-NEXT: [[CV:%.*]] = xor <2 x i8> [[B]], +; CHECK-NEXT: [[C:%.*]] = extractelement <2 x i8> [[CV]], i32 0 +; CHECK-NEXT: [[D:%.*]] = or i8 [[C]], 1 +; CHECK-NEXT: [[E:%.*]] = xor i8 [[D]], 12 +; CHECK-NEXT: ret i8 [[E]] ; %B = or <2 x i8> %A, %CV = xor <2 x i8> %B, Index: test/Transforms/InstSimplify/shift-knownbits.ll =================================================================== --- test/Transforms/InstSimplify/shift-knownbits.ll +++ test/Transforms/InstSimplify/shift-knownbits.ll @@ -154,7 +154,9 @@ define i32 @lshr_ctlz_zero_is_undef(i32 %x) { ; CHECK-LABEL: @lshr_ctlz_zero_is_undef( -; CHECK-NEXT: ret i32 0 +; CHECK-NEXT: [[CT:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X:%.*]], i1 true) +; CHECK-NEXT: [[SH:%.*]] = lshr i32 [[CT]], 5 +; CHECK-NEXT: ret i32 [[SH]] ; %ct = call i32 @llvm.ctlz.i32(i32 %x, i1 true) %sh = lshr i32 %ct, 5 @@ -163,7 +165,9 @@ define i32 @lshr_cttz_zero_is_undef(i32 %x) { ; CHECK-LABEL: @lshr_cttz_zero_is_undef( -; CHECK-NEXT: ret i32 0 +; CHECK-NEXT: [[CT:%.*]] = call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 true) +; CHECK-NEXT: [[SH:%.*]] = lshr i32 [[CT]], 5 +; CHECK-NEXT: ret i32 [[SH]] ; %ct = call i32 @llvm.cttz.i32(i32 %x, i1 true) %sh = lshr i32 %ct, 5 @@ -172,7 +176,9 @@ define <2 x i8> @lshr_ctlz_zero_is_undef_splat_vec(<2 x i8> %x) { ; CHECK-LABEL: @lshr_ctlz_zero_is_undef_splat_vec( -; CHECK-NEXT: ret <2 x i8> zeroinitializer +; CHECK-NEXT: [[CT:%.*]] = call <2 x i8> @llvm.ctlz.v2i8(<2 x i8> [[X:%.*]], i1 true) +; CHECK-NEXT: [[SH:%.*]] = lshr <2 x i8> [[CT]], +; CHECK-NEXT: ret <2 x i8> [[SH]] ; %ct = call <2 x i8> @llvm.ctlz.v2i8(<2 x i8> %x, i1 true) %sh = lshr <2 x i8> %ct, @@ -181,7 +187,10 @@ define i8 @lshr_ctlz_zero_is_undef_vec(<2 x i8> %x) { ; CHECK-LABEL: @lshr_ctlz_zero_is_undef_vec( -; CHECK-NEXT: ret i8 0 +; CHECK-NEXT: [[CT:%.*]] = call <2 x i8> @llvm.ctlz.v2i8(<2 x i8> [[X:%.*]], i1 true) +; CHECK-NEXT: [[SH:%.*]] = lshr <2 x i8> [[CT]], +; CHECK-NEXT: [[EX:%.*]] = extractelement <2 x i8> [[SH]], i32 0 +; CHECK-NEXT: ret i8 [[EX]] ; %ct = call <2 x i8> @llvm.ctlz.v2i8(<2 x i8> %x, i1 true) %sh = lshr <2 x i8> %ct, @@ -191,7 +200,9 @@ define <2 x i8> @lshr_cttz_zero_is_undef_splat_vec(<2 x i8> %x) { ; CHECK-LABEL: @lshr_cttz_zero_is_undef_splat_vec( -; CHECK-NEXT: ret <2 x i8> zeroinitializer +; CHECK-NEXT: [[CT:%.*]] = call <2 x i8> @llvm.cttz.v2i8(<2 x i8> [[X:%.*]], i1 true) +; CHECK-NEXT: [[SH:%.*]] = lshr <2 x i8> [[CT]], +; CHECK-NEXT: ret <2 x i8> [[SH]] ; %ct = call <2 x i8> @llvm.cttz.v2i8(<2 x i8> %x, i1 true) %sh = lshr <2 x i8> %ct, @@ -200,7 +211,10 @@ define i8 @lshr_cttz_zero_is_undef_vec(<2 x i8> %x) { ; CHECK-LABEL: @lshr_cttz_zero_is_undef_vec( -; CHECK-NEXT: ret i8 0 +; CHECK-NEXT: [[CT:%.*]] = call <2 x i8> @llvm.cttz.v2i8(<2 x i8> [[X:%.*]], i1 true) +; CHECK-NEXT: [[SH:%.*]] = lshr <2 x i8> [[CT]], +; CHECK-NEXT: [[EX:%.*]] = extractelement <2 x i8> [[SH]], i32 0 +; CHECK-NEXT: ret i8 [[EX]] ; %ct = call <2 x i8> @llvm.cttz.v2i8(<2 x i8> %x, i1 true) %sh = lshr <2 x i8> %ct,