[llvm] [LazyValueInfo] Support vector types in ICmp condition handling (PR #192900)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 19 23:44:56 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Jim Lin (tclin914)

<details>
<summary>Changes</summary>

Use m_APInt matcher instead of ConstantInt dyn_cast so splat vector constants are handled, and relax the integer type check to accept integer vector types.

Fixes https://github.com/llvm/llvm-project/issues/192094

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


2 Files Affected:

- (modified) llvm/lib/Analysis/LazyValueInfo.cpp (+4-3) 
- (modified) llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll (+14) 


``````````diff
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp
index bea5f70b03f02..05730eddd770b 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -1316,8 +1316,9 @@ LazyValueInfoImpl::getValueFromSimpleICmpCondition(CmpInst::Predicate Pred,
                                                    bool UseBlockValue) {
   ConstantRange RHSRange(RHS->getType()->getScalarSizeInBits(),
                          /*isFullSet=*/true);
-  if (ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
-    RHSRange = ConstantRange(CI->getValue());
+  const APInt *C;
+  if (match(RHS, m_APInt(C))) {
+    RHSRange = ConstantRange(*C);
   } else if (UseBlockValue) {
     std::optional<ValueLatticeElement> R =
         getBlockValue(RHS, CxtI->getParent(), CxtI);
@@ -1391,7 +1392,7 @@ std::optional<ValueLatticeElement> LazyValueInfoImpl::getValueFromICmpCondition(
   }
 
   Type *Ty = Val->getType();
-  if (!Ty->isIntegerTy())
+  if (!Ty->isIntOrIntVectorTy())
     return ValueLatticeElement::getOverdefined();
 
   unsigned BitWidth = Ty->getScalarSizeInBits();
diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll b/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll
index baf8f386a8cce..fbf77f76d3930 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll
@@ -219,6 +219,20 @@ define <2 x float> @sitofp(<2 x i8> %a) {
   ret <2 x float> %res
 }
 
+; The and is redundant when the icmp condition guarantees the value is in range.
+define <16 x i16> @select_and_icmp_vector(<16 x i16> noundef %x) {
+; CHECK-LABEL: define range(i16 0, 25) <16 x i16> @select_and_icmp_vector(
+; CHECK-SAME: <16 x i16> noundef [[X:%.*]]) {
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult <16 x i16> [[X]], splat (i16 8)
+; CHECK-NEXT:    [[SEL:%.*]] = select <16 x i1> [[CMP]], <16 x i16> [[X]], <16 x i16> splat (i16 24)
+; CHECK-NEXT:    ret <16 x i16> [[SEL]]
+;
+  %and = and <16 x i16> %x, splat (i16 7)
+  %cmp = icmp ult <16 x i16> %x, splat (i16 8)
+  %sel = select <16 x i1> %cmp, <16 x i16> %and, <16 x i16> splat (i16 24)
+  ret <16 x i16> %sel
+}
+
 define <2 x i16> @and(<2 x i8> %a) {
 ; CHECK-LABEL: define range(i16 0, 256) <2 x i16> @and(
 ; CHECK-SAME: <2 x i8> [[A:%.*]]) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/192900


More information about the llvm-commits mailing list