[PATCH] D143646: [RISCV] Return false from shouldFormOverflowOp when type is i8 and i16
Liao Chunyu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 8 04:49:27 PST 2023
liaolucy updated this revision to Diff 503325.
liaolucy retitled this revision from "[RISCV] Return false from shouldFormOverflowOp" to "[RISCV] Return false from shouldFormOverflowOp when type is i8 and i16".
liaolucy edited the summary of this revision.
liaolucy added a comment.
I found that i8 and i16 are better without overflow, so I kept it here and returned false when the data type is i8 and i16
overflow promote, LHS and RHS use ZExtPromotedInteger in PromoteIntRes_UADDSUBO.
add promote, LHS and RHS GetPromotedInteger int PromoteIntRes_SimpleIntBinOp.
Therefore the overflow has an extra zero extension instruction.
If there is another better way, I am willing to learn
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D143646/new/
https://reviews.llvm.org/D143646
Files:
llvm/lib/Target/RISCV/RISCVISelLowering.h
llvm/test/CodeGen/RISCV/overflow-intrinsics.ll
Index: llvm/test/CodeGen/RISCV/overflow-intrinsics.ll
===================================================================
--- llvm/test/CodeGen/RISCV/overflow-intrinsics.ll
+++ llvm/test/CodeGen/RISCV/overflow-intrinsics.ll
@@ -543,21 +543,17 @@
define i1 @uaddo_i8_increment_noncanonical_1(i8 %x, ptr %p) {
; RV32-LABEL: uaddo_i8_increment_noncanonical_1:
; RV32: # %bb.0:
-; RV32-NEXT: andi a0, a0, 255
; RV32-NEXT: addi a2, a0, 1
; RV32-NEXT: andi a0, a2, 255
-; RV32-NEXT: xor a0, a0, a2
-; RV32-NEXT: snez a0, a0
+; RV32-NEXT: seqz a0, a0
; RV32-NEXT: sb a2, 0(a1)
; RV32-NEXT: ret
;
; RV64-LABEL: uaddo_i8_increment_noncanonical_1:
; RV64: # %bb.0:
-; RV64-NEXT: andi a0, a0, 255
-; RV64-NEXT: addi a2, a0, 1
+; RV64-NEXT: addiw a2, a0, 1
; RV64-NEXT: andi a0, a2, 255
-; RV64-NEXT: xor a0, a0, a2
-; RV64-NEXT: snez a0, a0
+; RV64-NEXT: seqz a0, a0
; RV64-NEXT: sb a2, 0(a1)
; RV64-NEXT: ret
%a = add i8 1, %x ; commute
@@ -589,26 +585,20 @@
define i1 @uaddo_i16_increment_noncanonical_3(i16 %x, ptr %p) {
; RV32-LABEL: uaddo_i16_increment_noncanonical_3:
; RV32: # %bb.0:
-; RV32-NEXT: lui a2, 16
-; RV32-NEXT: addi a2, a2, -1
-; RV32-NEXT: and a0, a0, a2
-; RV32-NEXT: addi a3, a0, 1
-; RV32-NEXT: and a2, a3, a2
-; RV32-NEXT: xor a2, a2, a3
-; RV32-NEXT: snez a0, a2
-; RV32-NEXT: sh a3, 0(a1)
+; RV32-NEXT: addi a2, a0, 1
+; RV32-NEXT: slli a0, a2, 16
+; RV32-NEXT: srli a0, a0, 16
+; RV32-NEXT: seqz a0, a0
+; RV32-NEXT: sh a2, 0(a1)
; RV32-NEXT: ret
;
; RV64-LABEL: uaddo_i16_increment_noncanonical_3:
; RV64: # %bb.0:
-; RV64-NEXT: lui a2, 16
-; RV64-NEXT: addiw a2, a2, -1
-; RV64-NEXT: and a0, a0, a2
-; RV64-NEXT: addi a3, a0, 1
-; RV64-NEXT: and a2, a3, a2
-; RV64-NEXT: xor a2, a2, a3
-; RV64-NEXT: snez a0, a2
-; RV64-NEXT: sh a3, 0(a1)
+; RV64-NEXT: addiw a2, a0, 1
+; RV64-NEXT: slli a0, a2, 48
+; RV64-NEXT: srli a0, a0, 48
+; RV64-NEXT: seqz a0, a0
+; RV64-NEXT: sh a2, 0(a1)
; RV64-NEXT: ret
%a = add i16 1, %x ; commute
%ov = icmp eq i16 0, %a ; commute
Index: llvm/lib/Target/RISCV/RISCVISelLowering.h
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.h
+++ llvm/lib/Target/RISCV/RISCVISelLowering.h
@@ -485,6 +485,17 @@
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
EVT VT) const override;
+ bool shouldFormOverflowOp(unsigned Opcode, EVT VT,
+ bool MathUsed) const override {
+ if (Opcode != ISD::UADDO)
+ return false;
+
+ if (VT.isVector())
+ return false;
+
+ return MathUsed && (VT == MVT::i32 || VT == MVT::i64);
+ }
+
bool convertSetCCLogicToBitwiseLogic(EVT VT) const override {
return VT.isScalarInteger();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143646.503325.patch
Type: text/x-patch
Size: 2924 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230308/aa083a46/attachment.bin>
More information about the llvm-commits
mailing list