[PATCH] D56185: [BDCE] Remove instructions without demanded bits

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 1 04:41:56 PST 2019


nikic updated this revision to Diff 179794.
nikic retitled this revision from "[BDCE] Remove intructions without demanded bits" to "[BDCE] Remove instructions without demanded bits".
nikic added a comment.

Rebase over regenerated test checks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56185/new/

https://reviews.llvm.org/D56185

Files:
  lib/Transforms/Scalar/BDCE.cpp
  test/Transforms/BDCE/invalidate-assumptions.ll
  test/Transforms/BDCE/vectors.ll


Index: test/Transforms/BDCE/vectors.ll
===================================================================
--- test/Transforms/BDCE/vectors.ll
+++ 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:%.*]], <i32 1, i32 1>
 ; CHECK-NEXT:    [[A3:%.*]] = and <2 x i32> zeroinitializer, <i32 4, i32 4>
 ; CHECK-NEXT:    [[B2:%.*]] = add <2 x i32> [[B:%.*]], <i32 1, i32 1>
 ; CHECK-NEXT:    [[B3:%.*]] = and <2 x i32> [[B2]], <i32 8, i32 8>
@@ -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:%.*]], <i32 1, i32 1>
 ; CHECK-NEXT:    [[A3:%.*]] = and <2 x i32> zeroinitializer, <i32 4, i32 4>
 ; CHECK-NEXT:    [[B2:%.*]] = add <2 x i32> [[B:%.*]], <i32 1, i32 1>
 ; CHECK-NEXT:    [[B3:%.*]] = and <2 x i32> [[B2]], <i32 8, i32 8>
@@ -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, <i32 4, i32 4>
-; 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]], <i32 8, i32 8>
 ; CHECK-NEXT:    [[Z:%.*]] = or <2 x i32> [[X3]], [[Y3]]
 ; CHECK-NEXT:    [[U:%.*]] = ashr <2 x i32> [[Z]], <i32 3, i32 3>
@@ -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:%.*]], <i8 64, i8 64>
 ; CHECK-NEXT:    [[LITTLE_NUMBER:%.*]] = zext <2 x i1> [[B:%.*]] to <2 x i8>
 ; CHECK-NEXT:    [[BIG_NUMBER:%.*]] = shl <2 x i8> zeroinitializer, <i8 1, i8 1>
 ; CHECK-NEXT:    [[SUB:%.*]] = sub <2 x i8> [[BIG_NUMBER]], [[LITTLE_NUMBER]]
Index: test/Transforms/BDCE/invalidate-assumptions.ll
===================================================================
--- test/Transforms/BDCE/invalidate-assumptions.ll
+++ 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: lib/Transforms/Scalar/BDCE.cpp
===================================================================
--- lib/Transforms/Scalar/BDCE.cpp
+++ 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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56185.179794.patch
Type: text/x-patch
Size: 4611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190101/4de8acb7/attachment.bin>


More information about the llvm-commits mailing list