Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[SimplifyCFG] switch: Do Not Transform the Default Case if the Condition is Too Wide" #78469

Merged
merged 2 commits into from
Jan 17, 2024

Conversation

alexfh
Copy link
Contributor

@alexfh alexfh commented Jan 17, 2024

Reverts #77831, which depends on #76669, which seriously regresses compilation time / memory usage see #76669 (comment).

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 17, 2024

@llvm/pr-subscribers-llvm-transforms

Author: None (alexfh)

Changes

Reverts llvm/llvm-project#77831, which depends on #76669, which seriously regresses compilation time / memory usage see #76669 (comment).


Full diff: https://github.com/llvm/llvm-project/pull/78469.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/Utils/SimplifyCFG.cpp (-5)
  • (modified) llvm/test/Transforms/SimplifyCFG/switch-dead-default.ll (-33)
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index fe36fd84e0439b..7515e539e7fb78 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -5623,11 +5623,6 @@ static bool eliminateDeadSwitchCases(SwitchInst *SI, DomTreeUpdater *DTU,
     // optimization, such as lookup tables.
     if (SI->getNumCases() == AllNumCases - 1) {
       assert(NumUnknownBits > 1 && "Should be canonicalized to a branch");
-      IntegerType *CondTy = cast<IntegerType>(Cond->getType());
-      if (CondTy->getIntegerBitWidth() > 64 ||
-          !DL.fitsInLegalInteger(CondTy->getIntegerBitWidth()))
-        return false;
-
       uint64_t MissingCaseVal = 0;
       for (const auto &Case : SI->cases())
         MissingCaseVal ^= Case.getCaseValue()->getValue().getLimitedValue();
diff --git a/llvm/test/Transforms/SimplifyCFG/switch-dead-default.ll b/llvm/test/Transforms/SimplifyCFG/switch-dead-default.ll
index 4a457cc177e85c..e30a535c523237 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch-dead-default.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch-dead-default.ll
@@ -313,39 +313,6 @@ default:
 
 declare void @llvm.assume(i1)
 
-define zeroext i1 @test8(i128 %a) {
-; We should not transform conditions wider than 64 bit.
-; CHECK-LABEL: define zeroext i1 @test8(
-; CHECK-SAME: i128 [[A:%.*]]) {
-; CHECK-NEXT:  entry:
-; CHECK-NEXT:    [[TMP0:%.*]] = and i128 [[A]], 3894222643901120721397872246915072
-; CHECK-NEXT:    switch i128 [[TMP0]], label [[LOR_RHS:%.*]] [
-; CHECK-NEXT:      i128 1298074214633706907132624082305024, label [[LOR_END:%.*]]
-; CHECK-NEXT:      i128 2596148429267413814265248164610048, label [[LOR_END]]
-; CHECK-NEXT:      i128 3894222643901120721397872246915072, label [[LOR_END]]
-; CHECK-NEXT:    ]
-; CHECK:       lor.rhs:
-; CHECK-NEXT:    br label [[LOR_END]]
-; CHECK:       lor.end:
-; CHECK-NEXT:    [[TMP1:%.*]] = phi i1 [ true, [[ENTRY:%.*]] ], [ false, [[LOR_RHS]] ], [ true, [[ENTRY]] ], [ true, [[ENTRY]] ]
-; CHECK-NEXT:    ret i1 [[TMP1]]
-;
-entry:
-  %0 = and i128 %a, 3894222643901120721397872246915072
-  switch i128 %0, label %lor.rhs [
-  i128 1298074214633706907132624082305024, label %lor.end
-  i128 2596148429267413814265248164610048, label %lor.end
-  i128 3894222643901120721397872246915072, label %lor.end
-  ]
-
-lor.rhs:                                          ; preds = %entry
-  br label %lor.end
-
-lor.end:                                          ; preds = %entry, %entry, %entry, %lor.rhs
-  %1 = phi i1 [ true, %entry ], [ false, %lor.rhs ], [ true, %entry ], [ true, %entry ]
-  ret i1 %1
-}
-
 !0 = !{!"branch_weights", i32 8, i32 4, i32 2, i32 1}
 ;.
 ; CHECK: [[PROF0]] = !{!"branch_weights", i32 0, i32 4, i32 2, i32 1, i32 8}

…fault with that case (#76669)"

This reverts commit 7d81e07, which introduces a
compiler memory usage regression. See
#76669 (comment)
@alexfh alexfh merged commit 2d5cc1c into main Jan 17, 2024
3 of 4 checks passed
@alexfh alexfh deleted the revert-77831-fix_simplify_cfg_switch branch January 17, 2024 18:04
ampandey-1995 pushed a commit to ampandey-1995/llvm-project that referenced this pull request Jan 19, 2024
…the Condition is Too Wide" (llvm#78469)

Reverts llvm#77831, which depends on llvm#76669, which
seriously regresses compilation time / memory usage see
llvm#76669 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants