Skip to content

[LoopUnswitch] Remove redundant condition. (NFC) #107893

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

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

AmrDeveloper
Copy link
Member

Remove redundant condition from '!A || (A && B)' to '!A || B'

Fixes: #99799

@llvmbot
Copy link
Member

llvmbot commented Sep 9, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Amr Hesham (AmrDeveloper)

Changes

Remove redundant condition from '!A || (A && B)' to '!A || B'

Fixes: #99799


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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp (+1-2)
diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index c235d2fb2a5bd4..7d87df1805d1ea 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -770,8 +770,7 @@ static bool unswitchTrivialSwitch(Loop &L, SwitchInst &SI, DominatorTree &DT,
     // instruction in the block.
     auto *TI = BBToCheck.getTerminator();
     bool isUnreachable = isa<UnreachableInst>(TI);
-    return !isUnreachable ||
-           (isUnreachable && (BBToCheck.getFirstNonPHIOrDbg() != TI));
+    return !isUnreachable || (BBToCheck.getFirstNonPHIOrDbg() != TI);
   };
 
   SmallVector<int, 4> ExitCaseIndices;

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch. Would be good to update the title to be more precise, e.g. something like [LoopUnswitch] Remove redundant condition. (NFC)

@@ -770,8 +770,7 @@ static bool unswitchTrivialSwitch(Loop &L, SwitchInst &SI, DominatorTree &DT,
// instruction in the block.
auto *TI = BBToCheck.getTerminator();
bool isUnreachable = isa<UnreachableInst>(TI);
return !isUnreachable ||
(isUnreachable && (BBToCheck.getFirstNonPHIOrDbg() != TI));
return !isUnreachable || (BBToCheck.getFirstNonPHIOrDbg() != TI);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return !isUnreachable || (BBToCheck.getFirstNonPHIOrDbg() != TI);
return !isUnreachable || BBToCheck.getFirstNonPHIOrDbg() != TI;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure i will update it now, thanks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@AmrDeveloper AmrDeveloper changed the title [Transform] Remove redundant condition [LoopUnswitch] Remove redundant condition. (NFC) Sep 9, 2024
@AmrDeveloper AmrDeveloper requested a review from fhahn September 10, 2024 17:50
Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@AmrDeveloper AmrDeveloper merged commit ef7a847 into llvm:main Sep 12, 2024
8 checks passed
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.

llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp:773:27: style: Redundant condition
3 participants