Skip to content

Commit 537e0e1

Browse files
authored
[RISCV][GISel] Added GISelPredicateCodes to LeadingOnes*Mask (#119886)
1 parent 5528388 commit 537e0e1

File tree

5 files changed

+38
-34
lines changed

5 files changed

+38
-34
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,15 @@ def LeadingOnesMask : PatLeaf<(imm), [{
493493
if (!N->hasOneUse())
494494
return false;
495495
return !isInt<32>(N->getSExtValue()) && isMask_64(~N->getSExtValue());
496-
}], TrailingZeros>;
496+
}], TrailingZeros> {
497+
let GISelPredicateCode = [{
498+
if (!MRI.hasOneNonDBGUse(MI.getOperand(0).getReg()))
499+
return false;
500+
const auto &MO = MI.getOperand(1);
501+
return !isInt<32>(MO.getCImm()->getSExtValue()) &&
502+
isMask_64(~MO.getCImm()->getSExtValue());
503+
}];
504+
}
497505

498506
def TrailingOnesMask : PatLeaf<(imm), [{
499507
if (!N->hasOneUse())
@@ -520,7 +528,17 @@ def LeadingOnesWMask : PatLeaf<(imm), [{
520528
int64_t Imm = N->getSExtValue();
521529
return !isInt<32>(Imm) && isUInt<32>(Imm) && isShiftedMask_64(Imm) &&
522530
Imm != UINT64_C(0xffffffff);
523-
}], TrailingZeros>;
531+
}], TrailingZeros> {
532+
let GISelPredicateCode = [{
533+
if (!MRI.hasOneNonDBGUse(MI.getOperand(0).getReg()))
534+
return false;
535+
const auto &MO = MI.getOperand(1);
536+
int64_t Imm = MO.getCImm()->getSExtValue();
537+
return !isInt<32>(Imm) && isUInt<32>(Imm) && isShiftedMask_64(Imm) &&
538+
Imm != UINT64_C(0xffffffff);
539+
}];
540+
541+
}
524542

525543
//===----------------------------------------------------------------------===//
526544
// Instruction Formats

llvm/test/CodeGen/RISCV/GlobalISel/double-arith.ll

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,10 @@ define double @fsgnj_d(double %a, double %b) nounwind {
169169
;
170170
; RV64I-LABEL: fsgnj_d:
171171
; RV64I: # %bb.0:
172-
; RV64I-NEXT: li a2, -1
173172
; RV64I-NEXT: slli a0, a0, 1
174-
; RV64I-NEXT: slli a2, a2, 63
173+
; RV64I-NEXT: srli a1, a1, 63
175174
; RV64I-NEXT: srli a0, a0, 1
176-
; RV64I-NEXT: and a1, a1, a2
175+
; RV64I-NEXT: slli a1, a1, 63
177176
; RV64I-NEXT: or a0, a0, a1
178177
; RV64I-NEXT: ret
179178
%1 = call double @llvm.copysign.f64(double %a, double %b)
@@ -1354,12 +1353,11 @@ define double @fsgnjx_f64(double %x, double %y) nounwind {
13541353
; RV64I: # %bb.0:
13551354
; RV64I-NEXT: addi sp, sp, -16
13561355
; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
1357-
; RV64I-NEXT: li a2, -1
1358-
; RV64I-NEXT: li a3, 1023
1359-
; RV64I-NEXT: slli a2, a2, 63
1360-
; RV64I-NEXT: slli a3, a3, 52
1361-
; RV64I-NEXT: and a0, a0, a2
1362-
; RV64I-NEXT: or a0, a0, a3
1356+
; RV64I-NEXT: li a2, 1023
1357+
; RV64I-NEXT: srli a0, a0, 63
1358+
; RV64I-NEXT: slli a2, a2, 52
1359+
; RV64I-NEXT: slli a0, a0, 63
1360+
; RV64I-NEXT: or a0, a0, a2
13631361
; RV64I-NEXT: call __muldf3
13641362
; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
13651363
; RV64I-NEXT: addi sp, sp, 16

llvm/test/CodeGen/RISCV/GlobalISel/double-intrinsics.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,10 @@ define double @copysign_f64(double %a, double %b) nounwind {
721721
;
722722
; RV64I-LABEL: copysign_f64:
723723
; RV64I: # %bb.0:
724-
; RV64I-NEXT: li a2, -1
725724
; RV64I-NEXT: slli a0, a0, 1
726-
; RV64I-NEXT: slli a2, a2, 63
725+
; RV64I-NEXT: srli a1, a1, 63
727726
; RV64I-NEXT: srli a0, a0, 1
728-
; RV64I-NEXT: and a1, a1, a2
727+
; RV64I-NEXT: slli a1, a1, 63
729728
; RV64I-NEXT: or a0, a0, a1
730729
; RV64I-NEXT: ret
731730
%1 = call double @llvm.copysign.f64(double %a, double %b)

llvm/test/CodeGen/RISCV/GlobalISel/fp128.ll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,11 @@ define fp128 @fabs(fp128 %x) {
108108
define fp128 @fcopysign(fp128 %x, fp128 %y) {
109109
; CHECK-LABEL: fcopysign:
110110
; CHECK: # %bb.0:
111-
; CHECK-NEXT: li a2, -1
112111
; CHECK-NEXT: slli a1, a1, 1
113-
; CHECK-NEXT: slli a2, a2, 63
112+
; CHECK-NEXT: srli a3, a3, 63
114113
; CHECK-NEXT: srli a1, a1, 1
115-
; CHECK-NEXT: and a2, a3, a2
116-
; CHECK-NEXT: or a1, a1, a2
114+
; CHECK-NEXT: slli a3, a3, 63
115+
; CHECK-NEXT: or a1, a1, a3
117116
; CHECK-NEXT: ret
118117
%a = call fp128 @llvm.copysign.f128(fp128 %x, fp128 %y)
119118
ret fp128 %a

llvm/test/CodeGen/RISCV/GlobalISel/rv64zba.ll

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,12 @@ define i64 @zextw_i64(i64 %a) nounwind {
105105
; This makes sure targetShrinkDemandedConstant changes the and immmediate to
106106
; allow zext.w or slli+srli.
107107
define i64 @zextw_demandedbits_i64(i64 %0) {
108-
; RV64I-LABEL: zextw_demandedbits_i64:
109-
; RV64I: # %bb.0:
110-
; RV64I-NEXT: li a1, 1
111-
; RV64I-NEXT: slli a1, a1, 32
112-
; RV64I-NEXT: addi a1, a1, -2
113-
; RV64I-NEXT: and a0, a0, a1
114-
; RV64I-NEXT: ori a0, a0, 1
115-
; RV64I-NEXT: ret
116-
;
117-
; RV64ZBA-LABEL: zextw_demandedbits_i64:
118-
; RV64ZBA: # %bb.0:
119-
; RV64ZBA-NEXT: li a1, -2
120-
; RV64ZBA-NEXT: zext.w a1, a1
121-
; RV64ZBA-NEXT: and a0, a0, a1
122-
; RV64ZBA-NEXT: ori a0, a0, 1
123-
; RV64ZBA-NEXT: ret
108+
; CHECK-LABEL: zextw_demandedbits_i64:
109+
; CHECK: # %bb.0:
110+
; CHECK-NEXT: srliw a0, a0, 1
111+
; CHECK-NEXT: slli a0, a0, 1
112+
; CHECK-NEXT: ori a0, a0, 1
113+
; CHECK-NEXT: ret
124114
%2 = and i64 %0, 4294967294
125115
%3 = or i64 %2, 1
126116
ret i64 %3

0 commit comments

Comments
 (0)