Skip to content

Commit 0cf768e

Browse files
lukel97preames
andauthored
[RISCV] Handle disjoint or in RISCVGatherScatterLowering (#77800)
This patch adds support for the disjoint flag in the non-recursive case, as well as adding an additional check for it in the recursive case. Note that haveNoCommonBitsSet should be equivalent to having the disjoint flag set, and the check can be removed in a follow-up patch. Co-authored-by: Philip Reames <[email protected]> --------- Co-authored-by: Philip Reames <[email protected]>
1 parent fa5255e commit 0cf768e

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,15 @@ static std::pair<Value *, Value *> matchStridedStart(Value *Start,
136136
// multipled.
137137
auto *BO = dyn_cast<BinaryOperator>(Start);
138138
if (!BO || (BO->getOpcode() != Instruction::Add &&
139+
BO->getOpcode() != Instruction::Or &&
139140
BO->getOpcode() != Instruction::Shl &&
140141
BO->getOpcode() != Instruction::Mul))
141142
return std::make_pair(nullptr, nullptr);
142143

144+
if (BO->getOpcode() == Instruction::Or &&
145+
!cast<PossiblyDisjointInst>(BO)->isDisjoint())
146+
return std::make_pair(nullptr, nullptr);
147+
143148
// Look for an operand that is splatted.
144149
unsigned OtherIndex = 0;
145150
Value *Splat = getSplatValue(BO->getOperand(1));
@@ -163,6 +168,10 @@ static std::pair<Value *, Value *> matchStridedStart(Value *Start,
163168
switch (BO->getOpcode()) {
164169
default:
165170
llvm_unreachable("Unexpected opcode");
171+
case Instruction::Or:
172+
// TODO: We'd be better off creating disjoint or here, but we don't yet
173+
// have an IRBuilder API for that.
174+
[[fallthrough]];
166175
case Instruction::Add:
167176
Start = Builder.CreateAdd(Start, Splat);
168177
break;
@@ -241,7 +250,8 @@ bool RISCVGatherScatterLowering::matchStridedRecurrence(Value *Index, Loop *L,
241250
return false;
242251
case Instruction::Or:
243252
// We need to be able to treat Or as Add.
244-
if (!haveNoCommonBitsSet(BO->getOperand(0), BO->getOperand(1), *DL))
253+
if (!haveNoCommonBitsSet(BO->getOperand(0), BO->getOperand(1), *DL) &&
254+
!cast<PossiblyDisjointInst>(BO)->isDisjoint())
245255
return false;
246256
break;
247257
case Instruction::Add:

llvm/test/CodeGen/RISCV/rvv/strided-load-store.ll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,8 @@ define <vscale x 1 x i64> @straightline_offset_add(ptr %p, i64 %offset) {
183183

184184
define <vscale x 1 x i64> @straightline_offset_disjoint_or(ptr %p, i64 %offset) {
185185
; CHECK-LABEL: @straightline_offset_disjoint_or(
186-
; CHECK-NEXT: [[STEP:%.*]] = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()
187-
; CHECK-NEXT: [[STEP_SHL:%.*]] = shl <vscale x 1 x i64> [[STEP]], shufflevector (<vscale x 1 x i64> insertelement (<vscale x 1 x i64> poison, i64 1, i32 0), <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer)
188-
; CHECK-NEXT: [[OFFSETV:%.*]] = or disjoint <vscale x 1 x i64> [[STEP_SHL]], shufflevector (<vscale x 1 x i64> insertelement (<vscale x 1 x i64> poison, i64 1, i32 0), <vscale x 1 x i64> poison, <vscale x 1 x i32> zeroinitializer)
189-
; CHECK-NEXT: [[PTRS:%.*]] = getelementptr i32, ptr [[P:%.*]], <vscale x 1 x i64> [[OFFSETV]]
190-
; CHECK-NEXT: [[X:%.*]] = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0(<vscale x 1 x ptr> [[PTRS]], i32 8, <vscale x 1 x i1> shufflevector (<vscale x 1 x i1> insertelement (<vscale x 1 x i1> poison, i1 true, i64 0), <vscale x 1 x i1> poison, <vscale x 1 x i32> zeroinitializer), <vscale x 1 x i64> poison)
186+
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i32, ptr [[P:%.*]], i64 1
187+
; CHECK-NEXT: [[X:%.*]] = call <vscale x 1 x i64> @llvm.riscv.masked.strided.load.nxv1i64.p0.i64(<vscale x 1 x i64> poison, ptr [[TMP1]], i64 8, <vscale x 1 x i1> shufflevector (<vscale x 1 x i1> insertelement (<vscale x 1 x i1> poison, i1 true, i64 0), <vscale x 1 x i1> poison, <vscale x 1 x i32> zeroinitializer))
191188
; CHECK-NEXT: ret <vscale x 1 x i64> [[X]]
192189
;
193190
%step = call <vscale x 1 x i64> @llvm.experimental.stepvector.nxv1i64()

0 commit comments

Comments
 (0)