[llvm] [SCEV][LoopStrengthReduce] Avoid querying SCEV for non-SCEVable operands (PR #214902)
Jinpeng Wang via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 7 17:48:15 PDT 2026
https://github.com/jjppp created https://github.com/llvm/llvm-project/pull/214902
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
>From acf7ac885f8e2185632341aad813f822b4274897 Mon Sep 17 00:00:00 2001
From: jpwang <jpwang at smail.nju.edu.cn>
Date: Sat, 8 Aug 2026 08:43:35 +0800
Subject: [PATCH] [SCEV] Avoid querying SCEV for non-SCEVable operands
---
llvm/lib/Analysis/ScalarEvolution.cpp | 4 ++++
.../LoopStrengthReduce/scev-vector-shl-crash.ll | 17 +++++++++++++++++
2 files changed, 21 insertions(+)
create mode 100644 llvm/test/Transforms/LoopStrengthReduce/scev-vector-shl-crash.ll
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
+}
More information about the llvm-commits
mailing list