Index: llvm/trunk/lib/Transforms/Scalar/BDCE.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/BDCE.cpp +++ llvm/trunk/lib/Transforms/Scalar/BDCE.cpp @@ -96,8 +96,12 @@ if (I.mayHaveSideEffects() && I.use_empty()) continue; - // Remove instructions not reached during analysis. - if (DB.isInstructionDead(&I)) { + // Remove instructions that are dead, either because they were not reached + // during analysis or have no demanded bits. + if (DB.isInstructionDead(&I) || + (I.getType()->isIntOrIntVectorTy() && + DB.getDemandedBits(&I).isNullValue() && + wouldInstructionBeTriviallyDead(&I))) { salvageDebugInfo(I); Worklist.push_back(&I); I.dropAllReferences(); Index: llvm/trunk/test/Transforms/BDCE/invalidate-assumptions.ll =================================================================== --- llvm/trunk/test/Transforms/BDCE/invalidate-assumptions.ll +++ llvm/trunk/test/Transforms/BDCE/invalidate-assumptions.ll @@ -9,7 +9,6 @@ define i1 @PR33695(i1 %b, i8 %x) { ; CHECK-LABEL: @PR33695( -; CHECK-NEXT: [[SETBIT:%.*]] = or i8 [[X:%.*]], 64 ; CHECK-NEXT: [[LITTLE_NUMBER:%.*]] = zext i1 [[B:%.*]] to i8 ; CHECK-NEXT: [[BIG_NUMBER:%.*]] = shl i8 0, 1 ; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[BIG_NUMBER]], [[LITTLE_NUMBER]] @@ -29,10 +28,6 @@ define i64 @PR34037(i64 %m, i32 %r, i64 %j, i1 %b, i32 %k, i64 %p) { ; CHECK-LABEL: @PR34037( -; CHECK-NEXT: [[CONV:%.*]] = zext i32 [[R:%.*]] to i64 -; CHECK-NEXT: [[AND:%.*]] = and i64 [[M:%.*]], 0 -; CHECK-NEXT: [[NEG:%.*]] = xor i64 0, 34359738367 -; CHECK-NEXT: [[OR:%.*]] = or i64 [[J:%.*]], 0 ; CHECK-NEXT: [[SHL:%.*]] = shl i64 0, 29 ; CHECK-NEXT: [[CONV1:%.*]] = select i1 [[B:%.*]], i64 7, i64 0 ; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[SHL]], [[CONV1]] @@ -64,7 +59,6 @@ define i1 @poison_on_call_user_is_ok(i1 %b, i8 %x) { ; CHECK-LABEL: @poison_on_call_user_is_ok( -; CHECK-NEXT: [[SETBIT:%.*]] = or i8 [[X:%.*]], 64 ; CHECK-NEXT: [[LITTLE_NUMBER:%.*]] = zext i1 [[B:%.*]] to i8 ; CHECK-NEXT: [[BIG_NUMBER:%.*]] = shl i8 0, 1 ; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[BIG_NUMBER]], [[LITTLE_NUMBER]] Index: llvm/trunk/test/Transforms/BDCE/vectors.ll =================================================================== --- llvm/trunk/test/Transforms/BDCE/vectors.ll +++ llvm/trunk/test/Transforms/BDCE/vectors.ll @@ -5,7 +5,6 @@ define <2 x i32> @test_basic(<2 x i32> %a, <2 x i32> %b) { ; CHECK-LABEL: @test_basic( -; CHECK-NEXT: [[A2:%.*]] = add <2 x i32> [[A:%.*]], ; CHECK-NEXT: [[A3:%.*]] = and <2 x i32> zeroinitializer, ; CHECK-NEXT: [[B2:%.*]] = add <2 x i32> [[B:%.*]], ; CHECK-NEXT: [[B3:%.*]] = and <2 x i32> [[B2]], @@ -25,7 +24,6 @@ ; Going vector -> scalar define i32 @test_extractelement(<2 x i32> %a, <2 x i32> %b) { ; CHECK-LABEL: @test_extractelement( -; CHECK-NEXT: [[A2:%.*]] = add <2 x i32> [[A:%.*]], ; CHECK-NEXT: [[A3:%.*]] = and <2 x i32> zeroinitializer, ; CHECK-NEXT: [[B2:%.*]] = add <2 x i32> [[B:%.*]], ; CHECK-NEXT: [[B3:%.*]] = and <2 x i32> [[B2]], @@ -47,11 +45,9 @@ ; Going scalar -> vector define <2 x i32> @test_insertelement(i32 %a, i32 %b) { ; CHECK-LABEL: @test_insertelement( -; CHECK-NEXT: [[X:%.*]] = insertelement <2 x i32> undef, i32 [[A:%.*]], i32 0 -; CHECK-NEXT: [[X2:%.*]] = insertelement <2 x i32> zeroinitializer, i32 [[B:%.*]], i32 1 ; CHECK-NEXT: [[X3:%.*]] = and <2 x i32> zeroinitializer, -; CHECK-NEXT: [[Y:%.*]] = insertelement <2 x i32> undef, i32 [[B]], i32 0 -; CHECK-NEXT: [[Y2:%.*]] = insertelement <2 x i32> [[Y]], i32 [[A]], i32 1 +; CHECK-NEXT: [[Y:%.*]] = insertelement <2 x i32> undef, i32 [[B:%.*]], i32 0 +; CHECK-NEXT: [[Y2:%.*]] = insertelement <2 x i32> [[Y]], i32 [[A:%.*]], i32 1 ; CHECK-NEXT: [[Y3:%.*]] = and <2 x i32> [[Y2]], ; CHECK-NEXT: [[Z:%.*]] = or <2 x i32> [[X3]], [[Y3]] ; CHECK-NEXT: [[U:%.*]] = ashr <2 x i32> [[Z]], @@ -91,7 +87,6 @@ ; Assumption invalidation (adapted from invalidate-assumptions.ll) define <2 x i1> @test_assumption_invalidation(<2 x i1> %b, <2 x i8> %x) { ; CHECK-LABEL: @test_assumption_invalidation( -; CHECK-NEXT: [[SETBIT:%.*]] = or <2 x i8> [[X:%.*]], ; CHECK-NEXT: [[LITTLE_NUMBER:%.*]] = zext <2 x i1> [[B:%.*]] to <2 x i8> ; CHECK-NEXT: [[BIG_NUMBER:%.*]] = shl <2 x i8> zeroinitializer, ; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i8> [[BIG_NUMBER]], [[LITTLE_NUMBER]]