Skip to content

Commit d9a5f7b

Browse files
authored
[ConstantFold] Constant fold icmp of boolean scalable vectors (#142528)
Closes #142447.
1 parent 4b2cb11 commit d9a5f7b

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

llvm/lib/IR/ConstantFold.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,10 +1149,10 @@ Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate,
11491149
}
11501150

11511151
// If the comparison is a comparison between two i1's, simplify it.
1152-
if (C1->getType()->isIntegerTy(1)) {
1152+
if (C1->getType()->isIntOrIntVectorTy(1)) {
11531153
switch (Predicate) {
11541154
case ICmpInst::ICMP_EQ:
1155-
if (isa<ConstantInt>(C2))
1155+
if (isa<ConstantExpr>(C1))
11561156
return ConstantExpr::getXor(C1, ConstantExpr::getNot(C2));
11571157
return ConstantExpr::getXor(ConstantExpr::getNot(C1), C2);
11581158
case ICmpInst::ICMP_NE:

llvm/test/Transforms/InstSimplify/compare.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,6 +3465,26 @@ define i1 @icmp_eq_false_by_trunc(i8 %x) {
34653465
ret i1 %cmp
34663466
}
34673467

3468+
define <vscale x 8 x i1> @icmp_ne_i1_vec_constant_expr() {
3469+
; CHECK-LABEL: @icmp_ne_i1_vec_constant_expr(
3470+
; CHECK-NEXT: entry:
3471+
; CHECK-NEXT: ret <vscale x 8 x i1> insertelement (<vscale x 8 x i1> poison, i1 true, i64 0)
3472+
;
3473+
entry:
3474+
%cmp = icmp ne <vscale x 8 x i1> insertelement (<vscale x 8 x i1> poison, i1 true, i64 0), zeroinitializer
3475+
ret <vscale x 8 x i1> %cmp
3476+
}
3477+
3478+
define <vscale x 8 x i1> @icmp_eq_i1_vec_constant_expr_commuted() {
3479+
; CHECK-LABEL: @icmp_eq_i1_vec_constant_expr_commuted(
3480+
; CHECK-NEXT: entry:
3481+
; 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))
3482+
;
3483+
entry:
3484+
%cmp = icmp eq <vscale x 8 x i1> zeroinitializer, insertelement (<vscale x 8 x i1> poison, i1 true, i64 0)
3485+
ret <vscale x 8 x i1> %cmp
3486+
}
3487+
34683488
declare i64 @llvm.vscale.i64()
34693489

34703490
; TODO: Add coverage for global aliases, link once, etc..

0 commit comments

Comments
 (0)