[llvm] d9a5f7b - [ConstantFold] Constant fold icmp of boolean scalable vectors (#142528)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 3 04:51:25 PDT 2025
Author: Yingwei Zheng
Date: 2025-06-03T19:51:21+08:00
New Revision: d9a5f7b118bfc9ab4b7325fae25073729d8e08be
URL: https://github.com/llvm/llvm-project/commit/d9a5f7b118bfc9ab4b7325fae25073729d8e08be
DIFF: https://github.com/llvm/llvm-project/commit/d9a5f7b118bfc9ab4b7325fae25073729d8e08be.diff
LOG: [ConstantFold] Constant fold icmp of boolean scalable vectors (#142528)
Closes https://github.com/llvm/llvm-project/issues/142447.
Added:
Modified:
llvm/lib/IR/ConstantFold.cpp
llvm/test/Transforms/InstSimplify/compare.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 7e5fda229b858..b9db402fe9562 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -1149,10 +1149,10 @@ Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate,
}
// If the comparison is a comparison between two i1's, simplify it.
- if (C1->getType()->isIntegerTy(1)) {
+ if (C1->getType()->isIntOrIntVectorTy(1)) {
switch (Predicate) {
case ICmpInst::ICMP_EQ:
- if (isa<ConstantInt>(C2))
+ if (isa<ConstantExpr>(C1))
return ConstantExpr::getXor(C1, ConstantExpr::getNot(C2));
return ConstantExpr::getXor(ConstantExpr::getNot(C1), C2);
case ICmpInst::ICMP_NE:
diff --git a/llvm/test/Transforms/InstSimplify/compare.ll b/llvm/test/Transforms/InstSimplify/compare.ll
index 4192a59dc7134..97ac8f2ea47ea 100644
--- a/llvm/test/Transforms/InstSimplify/compare.ll
+++ b/llvm/test/Transforms/InstSimplify/compare.ll
@@ -3465,6 +3465,26 @@ define i1 @icmp_eq_false_by_trunc(i8 %x) {
ret i1 %cmp
}
+define <vscale x 8 x i1> @icmp_ne_i1_vec_constant_expr() {
+; CHECK-LABEL: @icmp_ne_i1_vec_constant_expr(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: ret <vscale x 8 x i1> insertelement (<vscale x 8 x i1> poison, i1 true, i64 0)
+;
+entry:
+ %cmp = icmp ne <vscale x 8 x i1> insertelement (<vscale x 8 x i1> poison, i1 true, i64 0), zeroinitializer
+ ret <vscale x 8 x i1> %cmp
+}
+
+define <vscale x 8 x i1> @icmp_eq_i1_vec_constant_expr_commuted() {
+; CHECK-LABEL: @icmp_eq_i1_vec_constant_expr_commuted(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: ret <vscale x 8 x i1> xor (<vscale x 8 x i1> insertelement (<vscale x 8 x i1> poison, i1 true, i64 0), <vscale x 8 x i1> splat (i1 true))
+;
+entry:
+ %cmp = icmp eq <vscale x 8 x i1> zeroinitializer, insertelement (<vscale x 8 x i1> poison, i1 true, i64 0)
+ ret <vscale x 8 x i1> %cmp
+}
+
declare i64 @llvm.vscale.i64()
; TODO: Add coverage for global aliases, link once, etc..
More information about the llvm-commits
mailing list