From da74d6f1e6410c93b4dd611c436a27ad451d431f Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 2 Jan 2019 20:02:14 +0000 Subject: [PATCH] [BDCE] Remove instructions without demanded bits If an instruction has no demanded bits, remove it directly during BDCE, instead of leaving it for something else to clean up. Differential Revision: https://reviews.llvm.org/D56185 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350257 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/BDCE.cpp | 8 ++++++-- test/Transforms/BDCE/invalidate-assumptions.ll | 6 ------ test/Transforms/BDCE/vectors.ll | 9 ++------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/Transforms/Scalar/BDCE.cpp b/lib/Transforms/Scalar/BDCE.cpp index 65a68c17977..b7312765213 100644 --- a/lib/Transforms/Scalar/BDCE.cpp +++ b/lib/Transforms/Scalar/BDCE.cpp @@ -96,8 +96,12 @@ static bool bitTrackingDCE(Function &F, DemandedBits &DB) { 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(); diff --git a/test/Transforms/BDCE/invalidate-assumptions.ll b/test/Transforms/BDCE/invalidate-assumptions.ll index d81267b4793..69a99b33d90 100644 --- a/test/Transforms/BDCE/invalidate-assumptions.ll +++ b/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 i1 @PR33695(i1 %b, i8 %x) { 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 @@ declare i1 @foo(i1) 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]] diff --git a/test/Transforms/BDCE/vectors.ll b/test/Transforms/BDCE/vectors.ll index f9d048cb705..63a85872680 100644 --- a/test/Transforms/BDCE/vectors.ll +++ b/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 @@ define <2 x i32> @test_basic(<2 x i32> %a, <2 x i32> %b) { ; 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 @@ define i32 @test_extractelement(<2 x i32> %a, <2 x i32> %b) { ; 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 @@ define <2 x i32> @test_conversion(<2 x i32> %a) { ; 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]] -- 2.50.1