Skip to content

[LSR] Replace casts with an equivalent std::as_const (NFC) #138980

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
May 8, 2025

Conversation

s-barannikov
Copy link
Contributor

The casts / std::as_const are used here to select const overload of begin()/end() so that the type of the returned iterator matches the type of J, which is const_iterator.

@llvmbot
Copy link
Member

llvmbot commented May 7, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Sergei Barannikov (s-barannikov)

Changes

The casts / std::as_const are used here to select const overload of begin()/end() so that the type of the returned iterator matches the type of J, which is const_iterator.


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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp (+2-4)
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 04719fb70552b..464e6e3b2ab97 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -3946,10 +3946,8 @@ void LSRInstance::GenerateReassociationsImpl(LSRUse &LU, unsigned LUIdx,
       continue;
 
     // Collect all operands except *J.
-    SmallVector<const SCEV *, 8> InnerAddOps(
-        ((const SmallVector<const SCEV *, 8> &)AddOps).begin(), J);
-    InnerAddOps.append(std::next(J),
-                       ((const SmallVector<const SCEV *, 8> &)AddOps).end());
+    SmallVector<const SCEV *, 8> InnerAddOps(std::as_const(AddOps).begin(), J);
+    InnerAddOps.append(std::next(J), std::as_const(AddOps).end());
 
     // Don't leave just a constant behind in a register if the constant could
     // be folded into an immediate field.

@s-barannikov s-barannikov requested a review from pfusik May 8, 2025 00:07
Copy link
Contributor

@pfusik pfusik left a comment

Choose a reason for hiding this comment

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

LGTM. Replacing C-style casts with C++17 as_const, already used in a few places: StaticAnalyzer, MLIR, MLIR elsewhere.

@s-barannikov s-barannikov merged commit cedeef6 into llvm:main May 8, 2025
13 checks passed
@s-barannikov s-barannikov deleted the lsr-as-const branch May 8, 2025 10:36
@llvm-ci
Copy link
Collaborator

llvm-ci commented May 8, 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/19657

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/10/48' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/./AllClangUnitTests-Clang-Unit-4008-10-48.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=48 GTEST_SHARD_INDEX=10 /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/unittests/./AllClangUnitTests
--

Note: This is test shard 11 of 48.
[==========] Running 510 tests from 105 test suites.
[----------] Global test environment set-up.
[----------] 1 test from MinimizeSourceToDependencyDirectivesTest
[ RUN      ] MinimizeSourceToDependencyDirectivesTest.DefineInvalidMacroArguments
[       OK ] MinimizeSourceToDependencyDirectivesTest.DefineInvalidMacroArguments (1 ms)
[----------] 1 test from MinimizeSourceToDependencyDirectivesTest (1 ms total)

[----------] 1 test from HeaderMapTest
[ RUN      ] HeaderMapTest.lookupFilenameTruncatedPrefix
[       OK ] HeaderMapTest.lookupFilenameTruncatedPrefix (0 ms)
[----------] 1 test from HeaderMapTest (0 ms total)

[----------] 1 test from ModuleDeclStateTest
[ RUN      ] ModuleDeclStateTest.NamedModuleImplementation
[       OK ] ModuleDeclStateTest.NamedModuleImplementation (5 ms)
[----------] 1 test from ModuleDeclStateTest (5 ms total)

[----------] 1 test from DxcModeTest
[ RUN      ] DxcModeTest.TargetProfileValidation
[       OK ] DxcModeTest.TargetProfileValidation (8 ms)
[----------] 1 test from DxcModeTest (8 ms total)

[----------] 1 test from MultilibTest
[ RUN      ] MultilibTest.SetPushback
[       OK ] MultilibTest.SetPushback (0 ms)
[----------] 1 test from MultilibTest (0 ms total)

[----------] 2 tests from ExprMutationAnalyzerTest
[ RUN      ] ExprMutationAnalyzerTest.CallUnresolved
[       OK ] ExprMutationAnalyzerTest.CallUnresolved (62 ms)
[ RUN      ] ExprMutationAnalyzerTest.RangeForNonArrayByConstRef
input.cc:1:103: warning: expression result unused [-Wunused-value]
    1 | struct V { const int* begin() const; const int* end() const; };void f() { V x; for (const int& e : x) e; }
      |                                                                                                       ^
[       OK ] ExprMutationAnalyzerTest.RangeForNonArrayByConstRef (7 ms)
[----------] 2 tests from ExprMutationAnalyzerTest (69 ms total)

[----------] 1 test from MacroExpansionContextTest
[ RUN      ] MacroExpansionContextTest.StringizingVariadicMacros
[       OK ] MacroExpansionContextTest.StringizingVariadicMacros (0 ms)
[----------] 1 test from MacroExpansionContextTest (0 ms total)

[----------] 1 test from EnvironmentTest
...

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.

4 participants