Skip to content

Commit 9c50606

Browse files
preamesyuxuanchen1997
authored andcommitted
[instcombine] Extend logical reduction canonicalization to scalable vectors (#99366)
Summary: These transformations do not depend on the type being fixed in size, so enable them for scalable vectors too. Unlike for fixed vectors, these are only a canonicalization - the bitcast lowering for and/or/add is not legal on a scalable vector type. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250914
1 parent 740cfd1 commit 9c50606

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,8 +3430,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
34303430
}
34313431

34323432
if (match(Arg, m_ZExtOrSExtOrSelf(m_Value(Vect)))) {
3433-
if (auto *FTy = dyn_cast<FixedVectorType>(Vect->getType()))
3434-
if (FTy->getElementType() == Builder.getInt1Ty()) {
3433+
if (auto *VTy = dyn_cast<VectorType>(Vect->getType()))
3434+
if (VTy->getElementType() == Builder.getInt1Ty()) {
34353435
Value *Res = Builder.CreateAddReduce(Vect);
34363436
if (Arg != Vect)
34373437
Res = Builder.CreateCast(cast<CastInst>(Arg)->getOpcode(), Res,
@@ -3460,8 +3460,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
34603460
}
34613461

34623462
if (match(Arg, m_ZExtOrSExtOrSelf(m_Value(Vect)))) {
3463-
if (auto *FTy = dyn_cast<FixedVectorType>(Vect->getType()))
3464-
if (FTy->getElementType() == Builder.getInt1Ty()) {
3463+
if (auto *VTy = dyn_cast<VectorType>(Vect->getType()))
3464+
if (VTy->getElementType() == Builder.getInt1Ty()) {
34653465
Value *Res = Builder.CreateAndReduce(Vect);
34663466
if (Res->getType() != II->getType())
34673467
Res = Builder.CreateZExt(Res, II->getType());
@@ -3491,8 +3491,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
34913491
}
34923492

34933493
if (match(Arg, m_ZExtOrSExtOrSelf(m_Value(Vect)))) {
3494-
if (auto *FTy = dyn_cast<FixedVectorType>(Vect->getType()))
3495-
if (FTy->getElementType() == Builder.getInt1Ty()) {
3494+
if (auto *VTy = dyn_cast<VectorType>(Vect->getType()))
3495+
if (VTy->getElementType() == Builder.getInt1Ty()) {
34963496
Value *Res = IID == Intrinsic::vector_reduce_umin
34973497
? Builder.CreateAndReduce(Vect)
34983498
: Builder.CreateOrReduce(Vect);
@@ -3533,8 +3533,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
35333533
}
35343534

35353535
if (match(Arg, m_ZExtOrSExtOrSelf(m_Value(Vect)))) {
3536-
if (auto *FTy = dyn_cast<FixedVectorType>(Vect->getType()))
3537-
if (FTy->getElementType() == Builder.getInt1Ty()) {
3536+
if (auto *VTy = dyn_cast<VectorType>(Vect->getType()))
3537+
if (VTy->getElementType() == Builder.getInt1Ty()) {
35383538
Instruction::CastOps ExtOpc = Instruction::CastOps::CastOpsEnd;
35393539
if (Arg != Vect)
35403540
ExtOpc = cast<CastInst>(Arg)->getOpcode();

llvm/test/Transforms/InstCombine/vector-logical-reductions.ll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ define i1 @reduction_logical_mul(<2 x i1> %x) {
5151

5252
define i1 @reduction_logical_mul_nxv2i1(<vscale x 2 x i1> %x) {
5353
; CHECK-LABEL: @reduction_logical_mul_nxv2i1(
54-
; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.mul.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
54+
; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.and.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
5555
; CHECK-NEXT: ret i1 [[R]]
5656
;
5757
%r = call i1 @llvm.vector.reduce.mul.nxv2i1(<vscale x 2 x i1> %x)
@@ -71,7 +71,7 @@ define i1 @reduction_logical_xor(<2 x i1> %x) {
7171

7272
define i1 @reduction_logical_xor_nxv2i1(<vscale x 2 x i1> %x) {
7373
; CHECK-LABEL: @reduction_logical_xor_nxv2i1(
74-
; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.xor.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
74+
; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.add.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
7575
; CHECK-NEXT: ret i1 [[R]]
7676
;
7777
%r = call i1 @llvm.vector.reduce.xor.nxv2i1(<vscale x 2 x i1> %x)
@@ -90,7 +90,7 @@ define i1 @reduction_logical_smin(<2 x i1> %x) {
9090

9191
define i1 @reduction_logical_smin_nxv2i1(<vscale x 2 x i1> %x) {
9292
; CHECK-LABEL: @reduction_logical_smin_nxv2i1(
93-
; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.smin.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
93+
; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.or.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
9494
; CHECK-NEXT: ret i1 [[R]]
9595
;
9696
%r = call i1 @llvm.vector.reduce.smin.nxv2i1(<vscale x 2 x i1> %x)
@@ -109,7 +109,7 @@ define i1 @reduction_logical_smax(<2 x i1> %x) {
109109

110110
define i1 @reduction_logical_smax_nxv2i1(<vscale x 2 x i1> %x) {
111111
; CHECK-LABEL: @reduction_logical_smax_nxv2i1(
112-
; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.smax.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
112+
; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.and.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
113113
; CHECK-NEXT: ret i1 [[R]]
114114
;
115115
%r = call i1 @llvm.vector.reduce.smax.nxv2i1(<vscale x 2 x i1> %x)
@@ -128,7 +128,7 @@ define i1 @reduction_logical_umin(<2 x i1> %x) {
128128

129129
define i1 @reduction_logical_umin_nxv2i1(<vscale x 2 x i1> %x) {
130130
; CHECK-LABEL: @reduction_logical_umin_nxv2i1(
131-
; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.umin.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
131+
; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.and.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
132132
; CHECK-NEXT: ret i1 [[R]]
133133
;
134134
%r = call i1 @llvm.vector.reduce.umin.nxv2i1(<vscale x 2 x i1> %x)
@@ -147,7 +147,7 @@ define i1 @reduction_logical_umax(<2 x i1> %x) {
147147

148148
define i1 @reduction_logical_umax_nxv2i1(<vscale x 2 x i1> %x) {
149149
; CHECK-LABEL: @reduction_logical_umax_nxv2i1(
150-
; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.umax.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
150+
; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.or.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
151151
; CHECK-NEXT: ret i1 [[R]]
152152
;
153153
%r = call i1 @llvm.vector.reduce.umax.nxv2i1(<vscale x 2 x i1> %x)
@@ -199,7 +199,7 @@ define i1 @reduction_logical_and_reverse_v2i1(<2 x i1> %p) {
199199

200200
define i1 @reduction_logical_xor_reverse_nxv2i1(<vscale x 2 x i1> %p) {
201201
; CHECK-LABEL: @reduction_logical_xor_reverse_nxv2i1(
202-
; CHECK-NEXT: [[RED:%.*]] = call i1 @llvm.vector.reduce.xor.nxv2i1(<vscale x 2 x i1> [[P:%.*]])
202+
; CHECK-NEXT: [[RED:%.*]] = call i1 @llvm.vector.reduce.add.nxv2i1(<vscale x 2 x i1> [[P:%.*]])
203203
; CHECK-NEXT: ret i1 [[RED]]
204204
;
205205
%rev = call <vscale x 2 x i1> @llvm.vector.reverse.nxv2i1(<vscale x 2 x i1> %p)

0 commit comments

Comments
 (0)