Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[IR] Convert check to assertion in PredIterator (NFC) #137931

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
Apr 30, 2025

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Apr 30, 2025

After #137799 and #137816, instruction uses of BasicBlocks are always terminators, so assert that instead of checking it.

This is a small compile-time improvement: https://llvm-compile-time-tracker.com/compare.php?from=a618ae2c729152133440315f7b2f23e4612b39f8&to=5a60dadb74fa0c5f68642a184ed3d592c185c421&stat=instructions:u

After llvm#137799 and
llvm#137816, instruction uses
of BasicBlocks are always terminators, so assert that instead of
checking it.
@nikic nikic requested review from arsenm, fhahn and dtcxzyw April 30, 2025 07:44
@llvmbot
Copy link
Member

llvmbot commented Apr 30, 2025

@llvm/pr-subscribers-llvm-ir

Author: Nikita Popov (nikic)

Changes

After #137799 and #137816, instruction uses of BasicBlocks are always terminators, so assert that instead of checking it.

This is a small compile-time improvement: https://llvm-compile-time-tracker.com/compare.php?from=a618ae2c729152133440315f7b2f23e4612b39f8&to=5a60dadb74fa0c5f68642a184ed3d592c185c421&stat=instructions:u


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

1 Files Affected:

  • (modified) llvm/include/llvm/IR/CFG.h (+4-3)
diff --git a/llvm/include/llvm/IR/CFG.h b/llvm/include/llvm/IR/CFG.h
index f8ec0971517a9..7c7e988fa9e8f 100644
--- a/llvm/include/llvm/IR/CFG.h
+++ b/llvm/include/llvm/IR/CFG.h
@@ -54,9 +54,10 @@ class PredIterator {
   inline void advancePastNonTerminators() {
     // Loop to ignore non-terminator uses (for example BlockAddresses).
     while (!It.atEnd()) {
-      if (auto *Inst = dyn_cast<Instruction>(*It))
-        if (Inst->isTerminator())
-          break;
+      if (auto *Inst = dyn_cast<Instruction>(*It)) {
+        assert(Inst->isTerminator() && "BasicBlock used in non-terminator");
+        break;
+      }
 
       ++It;
     }

@nikic nikic merged commit 1cf1dc3 into llvm:main Apr 30, 2025
13 checks passed
@nikic nikic deleted the pred-iter-terminator branch April 30, 2025 10:22
@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 30, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-4 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/19255

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang-Unit :: ./AllClangUnitTests/39/51' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/./AllClangUnitTests-Clang-Unit-48740-39-51.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=51 GTEST_SHARD_INDEX=39 /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/./AllClangUnitTests
--

Script:
--
/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/./AllClangUnitTests --gtest_filter=TimeProfilerTest.ConstantEvaluationC99
--
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/unittests/Support/TimeProfilerTest.cpp:347: Failure
Expected equality of these values:
  R"(
Frontend (test.c)
| ParseDeclarationOrFunctionDefinition (test.c:2:1)
| | isIntegerConstantExpr (<test.c:3:18>)
| | EvaluateKnownConstIntCheckOverflow (<test.c:3:18>)
| PerformPendingInstantiations
)"
    Which is: "\nFrontend (test.c)\n| ParseDeclarationOrFunctionDefinition (test.c:2:1)\n| | isIntegerConstantExpr (<test.c:3:18>)\n| | EvaluateKnownConstIntCheckOverflow (<test.c:3:18>)\n| PerformPendingInstantiations\n"
  buildTraceGraph(Json)
    Which is: "\nFrontend (test.c)\n| ParseDeclarationOrFunctionDefinition (test.c:2:1)\n| | isIntegerConstantExpr (<test.c:3:18>)\n| | EvaluateKnownConstIntCheckOverflow (<test.c:3:18>)\n| | PerformPendingInstantiations\n"
With diff:
@@ -4,3 +4,3 @@
 | | isIntegerConstantExpr (<test.c:3:18>)
 | | EvaluateKnownConstIntCheckOverflow (<test.c:3:18>)
-| PerformPendingInstantiations\n
+| | PerformPendingInstantiations\n



/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/unittests/Support/TimeProfilerTest.cpp:347
Expected equality of these values:
  R"(
Frontend (test.c)
| ParseDeclarationOrFunctionDefinition (test.c:2:1)
| | isIntegerConstantExpr (<test.c:3:18>)
| | EvaluateKnownConstIntCheckOverflow (<test.c:3:18>)
| PerformPendingInstantiations
)"
    Which is: "\nFrontend (test.c)\n| ParseDeclarationOrFunctionDefinition (test.c:2:1)\n| | isIntegerConstantExpr (<test.c:3:18>)\n| | EvaluateKnownConstIntCheckOverflow (<test.c:3:18>)\n| PerformPendingInstantiations\n"
  buildTraceGraph(Json)
    Which is: "\nFrontend (test.c)\n| ParseDeclarationOrFunctionDefinition (test.c:2:1)\n| | isIntegerConstantExpr (<test.c:3:18>)\n| | EvaluateKnownConstIntCheckOverflow (<test.c:3:18>)\n| | PerformPendingInstantiations\n"
With diff:
@@ -4,3 +4,3 @@
 | | isIntegerConstantExpr (<test.c:3:18>)
 | | EvaluateKnownConstIntCheckOverflow (<test.c:3:18>)
-| PerformPendingInstantiations\n
+| | PerformPendingInstantiations\n

...

IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
After llvm#137799 and
llvm#137816, instruction uses of
BasicBlocks are always terminators, so assert that instead of checking
it.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
After llvm#137799 and
llvm#137816, instruction uses of
BasicBlocks are always terminators, so assert that instead of checking
it.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
After llvm#137799 and
llvm#137816, instruction uses of
BasicBlocks are always terminators, so assert that instead of checking
it.
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
After llvm#137799 and
llvm#137816, instruction uses of
BasicBlocks are always terminators, so assert that instead of checking
it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants