Skip to content

Commit 94af475

Browse files
committed
address comments: remove redundant andi
1 parent 2ffde95 commit 94af475

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,14 +2814,11 @@ LoongArchTargetLowering::lowerEXTRACT_VECTOR_ELT(SDValue Op,
28142814
DAG.getNode(LoongArchISD::XVPERM, DL, MVT::v8i32, NewVec, SplatIdx);
28152815
SDValue SplatVec = DAG.getBitcast(VecTy, SplatValue);
28162816

2817-
// Compute the local index of the original i8/i16 element within the
2818-
// i32 element and then use it to broadcast the vector. Each elements
2819-
// of the vector will be the desired element.
2820-
SDValue LocalIdx = DAG.getNode(
2821-
ISD::AND, DL, GRLenVT, Idx,
2822-
DAG.getConstant(((VecTy == MVT::v32i8) ? 3 : 1), DL, GRLenVT));
2817+
// The original i8/i16 elements in each i32 lane all share the same i32
2818+
// intra-element offset, use the original Idx to broadcast the vector.
2819+
// Each elements of the vector will be the desired element.
28232820
SDValue ExtractVec =
2824-
DAG.getNode(LoongArchISD::VREPLVE, DL, VecTy, SplatVec, LocalIdx);
2821+
DAG.getNode(LoongArchISD::VREPLVE, DL, VecTy, SplatVec, Idx);
28252822

28262823
return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, ExtractVec,
28272824
DAG.getConstant(0, DL, GRLenVT));

llvm/test/CodeGen/LoongArch/lasx/ir-instruction/extractelement.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ define void @extract_32xi8_idx(ptr %src, ptr %dst, i32 %idx) nounwind {
8080
; CHECK-NEXT: srai.d $a0, $a2, 2
8181
; CHECK-NEXT: xvreplgr2vr.w $xr1, $a0
8282
; CHECK-NEXT: xvperm.w $xr0, $xr0, $xr1
83-
; CHECK-NEXT: andi $a0, $a2, 3
84-
; CHECK-NEXT: xvreplve.b $xr0, $xr0, $a0
83+
; CHECK-NEXT: xvreplve.b $xr0, $xr0, $a2
8584
; CHECK-NEXT: xvstelm.b $xr0, $a1, 0, 0
8685
; CHECK-NEXT: ret
8786
%v = load volatile <32 x i8>, ptr %src
@@ -97,8 +96,7 @@ define void @extract_16xi16_idx(ptr %src, ptr %dst, i32 %idx) nounwind {
9796
; CHECK-NEXT: srai.d $a0, $a2, 1
9897
; CHECK-NEXT: xvreplgr2vr.w $xr1, $a0
9998
; CHECK-NEXT: xvperm.w $xr0, $xr0, $xr1
100-
; CHECK-NEXT: andi $a0, $a2, 1
101-
; CHECK-NEXT: xvreplve.h $xr0, $xr0, $a0
99+
; CHECK-NEXT: xvreplve.h $xr0, $xr0, $a2
102100
; CHECK-NEXT: xvstelm.h $xr0, $a1, 0, 0
103101
; CHECK-NEXT: ret
104102
%v = load volatile <16 x i16>, ptr %src

0 commit comments

Comments
 (0)