Skip to content

Commit b61e387

Browse files
committed
Revert "[InstCombine] Match scalable splats in m_ImmConstant (llvm#132522)"
This reverts commit df9e5ae. This is triggering an assertion failure on llvm-test-suite with -enable-vplan-native-path: https://lab.llvm.org/buildbot/#/builders/198/builds/3365
1 parent 18dd299 commit b61e387

File tree

5 files changed

+14
-66
lines changed

5 files changed

+14
-66
lines changed

llvm/include/llvm/IR/PatternMatch.h

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -858,51 +858,18 @@ inline bind_ty<const BasicBlock> m_BasicBlock(const BasicBlock *&V) {
858858
return V;
859859
}
860860

861-
// TODO: Remove once UseConstant{Int,FP}ForScalableSplat is enabled by default,
862-
// and use m_Unless(m_ConstantExpr).
863-
struct immconstant_ty {
864-
template <typename ITy> static bool isImmConstant(ITy *V) {
865-
if (auto *CV = dyn_cast<Constant>(V)) {
866-
if (!isa<ConstantExpr>(CV) && !CV->containsConstantExpression())
867-
return true;
868-
869-
if (CV->getType()->isVectorTy()) {
870-
if (auto *Splat = CV->getSplatValue(/*AllowPoison=*/true)) {
871-
if (!isa<ConstantExpr>(Splat) &&
872-
!Splat->containsConstantExpression()) {
873-
return true;
874-
}
875-
}
876-
}
877-
}
878-
return false;
879-
}
880-
};
881-
882-
struct match_immconstant_ty : immconstant_ty {
883-
template <typename ITy> bool match(ITy *V) { return isImmConstant(V); }
884-
};
885-
886861
/// Match an arbitrary immediate Constant and ignore it.
887-
inline match_immconstant_ty m_ImmConstant() { return match_immconstant_ty(); }
888-
889-
struct bind_immconstant_ty : immconstant_ty {
890-
Constant *&VR;
891-
892-
bind_immconstant_ty(Constant *&V) : VR(V) {}
893-
894-
template <typename ITy> bool match(ITy *V) {
895-
if (isImmConstant(V)) {
896-
VR = cast<Constant>(V);
897-
return true;
898-
}
899-
return false;
900-
}
901-
};
862+
inline match_combine_and<class_match<Constant>,
863+
match_unless<constantexpr_match>>
864+
m_ImmConstant() {
865+
return m_CombineAnd(m_Constant(), m_Unless(m_ConstantExpr()));
866+
}
902867

903868
/// Match an immediate Constant, capturing the value if we match.
904-
inline bind_immconstant_ty m_ImmConstant(Constant *&C) {
905-
return bind_immconstant_ty(C);
869+
inline match_combine_and<bind_ty<Constant>,
870+
match_unless<constantexpr_match>>
871+
m_ImmConstant(Constant *&C) {
872+
return m_CombineAnd(m_Constant(C), m_Unless(m_ConstantExpr()));
906873
}
907874

908875
/// Match a specified Value*.

llvm/test/Transforms/InstCombine/select.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3519,7 +3519,8 @@ define <vscale x 2 x i32> @scalable_sign_bits(<vscale x 2 x i8> %x) {
35193519

35203520
define <vscale x 2 x i1> @scalable_non_zero(<vscale x 2 x i32> %x) {
35213521
; CHECK-LABEL: @scalable_non_zero(
3522-
; CHECK-NEXT: [[CMP:%.*]] = icmp ult <vscale x 2 x i32> [[X:%.*]], splat (i32 56)
3522+
; CHECK-NEXT: [[A:%.*]] = or <vscale x 2 x i32> [[X:%.*]], splat (i32 1)
3523+
; CHECK-NEXT: [[CMP:%.*]] = icmp ult <vscale x 2 x i32> [[A]], splat (i32 57)
35233524
; CHECK-NEXT: ret <vscale x 2 x i1> [[CMP]]
35243525
;
35253526
%a = or <vscale x 2 x i32> %x, splat (i32 1)

llvm/test/Transforms/InstCombine/shl-bo.ll

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -656,14 +656,3 @@ define <16 x i8> @test_FoldShiftByConstant_CreateAnd(<16 x i8> %in0) {
656656
%vshl_n = shl <16 x i8> %tmp, <i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5>
657657
ret <16 x i8> %vshl_n
658658
}
659-
660-
define <vscale x 1 x i8> @test_FoldShiftByConstant_CreateAnd_scalable(<vscale x 1 x i8> %x) {
661-
; CHECK-LABEL: @test_FoldShiftByConstant_CreateAnd_scalable(
662-
; CHECK-NEXT: [[TMP1:%.*]] = shl <vscale x 1 x i8> [[X:%.*]], splat (i8 2)
663-
; CHECK-NEXT: [[TMP2:%.*]] = and <vscale x 1 x i8> [[TMP1]], splat (i8 8)
664-
; CHECK-NEXT: ret <vscale x 1 x i8> [[TMP2]]
665-
;
666-
%1 = and <vscale x 1 x i8> %x, splat (i8 2)
667-
%2 = shl <vscale x 1 x i8> %1, splat (i8 2)
668-
ret <vscale x 1 x i8> %2
669-
}

llvm/test/Transforms/InstCombine/shl-twice-constant.ll

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,3 @@ define i64 @testfunc() {
1414
%shl2 = shl i64 %shl1, ptrtoint (ptr @c to i64)
1515
ret i64 %shl2
1616
}
17-
18-
define <vscale x 1 x i64> @scalable() {
19-
; CHECK-LABEL: @scalable(
20-
; CHECK-NEXT: [[SHL1:%.*]] = shl nuw <vscale x 1 x i64> splat (i64 1), shufflevector (<vscale x 1 x i64> insertelement (<vscale x 1 x i64> poison, i64 ptrtoint (ptr @c2 to i64), i64 0), <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer)
21-
; CHECK-NEXT: [[SHL2:%.*]] = shl <vscale x 1 x i64> [[SHL1]], shufflevector (<vscale x 1 x i64> insertelement (<vscale x 1 x i64> poison, i64 ptrtoint (ptr @c to i64), i64 0), <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer)
22-
; CHECK-NEXT: ret <vscale x 1 x i64> [[SHL2]]
23-
;
24-
%shl1 = shl <vscale x 1 x i64> splat (i64 1), splat (i64 ptrtoint (ptr @c2 to i64))
25-
%shl2 = shl <vscale x 1 x i64> %shl1, splat (i64 ptrtoint (ptr @c to i64))
26-
ret <vscale x 1 x i64> %shl2
27-
}

llvm/test/Transforms/InstCombine/sub.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,9 +857,11 @@ define <2 x i16> @test44vecminval(<2 x i16> %x) {
857857
ret <2 x i16> %sub
858858
}
859859

860+
; FIXME: This isn't combined to xor as above because the pattern in visitSub
861+
; uses m_ImmConstant which matches Constant but (explicitly) not ConstantExpr.
860862
define <vscale x 2 x i16> @test44scalablevecminval(<vscale x 2 x i16> %x) {
861863
; CHECK-LABEL: @test44scalablevecminval(
862-
; CHECK-NEXT: [[SUB:%.*]] = xor <vscale x 2 x i16> [[X:%.*]], splat (i16 -32768)
864+
; CHECK-NEXT: [[SUB:%.*]] = add <vscale x 2 x i16> [[X:%.*]], splat (i16 -32768)
863865
; CHECK-NEXT: ret <vscale x 2 x i16> [[SUB]]
864866
;
865867
%sub = sub nsw <vscale x 2 x i16> %x, splat (i16 -32768)

0 commit comments

Comments
 (0)