[llvm] [SCEV][LoopStrengthReduce] Avoid querying SCEV for non-SCEVable operands (PR #214902)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 7 17:48:49 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Jinpeng Wang (jjppp)
<details>
<summary>Changes</summary>
Checks the operand types before querying their SCEVs and bail out when either operand is not SCEVable.
`getStrengthenedNoWrapFlagsFromBinOp()` calls `getSCEV()` for both operands before checking whether the instruction is a supported binary operation.
For vector-typed operands, this triggers the assertion in `getSCEV()`, because vector types are not SCEVable.
The added test is a crash regression test.
Fixes #<!-- -->214782
---
Full diff: https://github.com/llvm/llvm-project/pull/214902.diff
2 Files Affected:
- (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+4)
- (added) llvm/test/Transforms/LoopStrengthReduce/scev-vector-shl-crash.ll (+17)
``````````diff
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 27a1a20bcdf79..03e18b4606efd 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -2433,6 +2433,10 @@ ScalarEvolution::getStrengthenedNoWrapFlagsFromBinOp(
bool Deduced = false;
+ if (!isSCEVable(OBO->getOperand(0)->getType()) ||
+ !isSCEVable(OBO->getOperand(1)->getType()))
+ return std::nullopt;
+
Instruction::BinaryOps Opcode = (Instruction::BinaryOps)OBO->getOpcode();
const SCEV *LHS = getSCEV(OBO->getOperand(0));
const SCEV *RHS = getSCEV(OBO->getOperand(1));
diff --git a/llvm/test/Transforms/LoopStrengthReduce/scev-vector-shl-crash.ll b/llvm/test/Transforms/LoopStrengthReduce/scev-vector-shl-crash.ll
new file mode 100644
index 0000000000000..6726231c24633
--- /dev/null
+++ b/llvm/test/Transforms/LoopStrengthReduce/scev-vector-shl-crash.ll
@@ -0,0 +1,17 @@
+; RUN: llc -mtriple=x86_64 < %s -o /dev/null
+define void @snork(i64 %arg) {
+bbl:
+ %shl = shl nsw <2 x i64> zeroinitializer, zeroinitializer
+ %extractelement = extractelement <2 x i64> %shl, i64 0
+ %sub = sub i64 %arg, %extractelement
+ %and = and i64 %arg, 1
+ %sub1 = sub i64 %sub, %and
+ %add = add i64 %extractelement, %sub1
+ br label %bbl2
+
+bbl2:
+ %phi = phi i64 [ %add3, %bbl2 ], [ %add, %bbl ]
+ %add3 = add i64 %phi, 1
+ %icmp = icmp eq i64 %add3, 0
+ br label %bbl2
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/214902
More information about the llvm-commits
mailing list