[PATCH] D32944: [NVPTX] Add support for ISD::ABS lowering
Simon Pilgrim via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat May 6 10:20:39 PDT 2017
RKSimon created this revision.
Herald added a subscriber: jholewinski.
Use the ISD::ABS opcode directly
Repository:
rL LLVM
https://reviews.llvm.org/D32944
Files:
lib/Target/NVPTX/NVPTXISelLowering.cpp
lib/Target/NVPTX/NVPTXInstrInfo.td
Index: lib/Target/NVPTX/NVPTXInstrInfo.td
===================================================================
--- lib/Target/NVPTX/NVPTXInstrInfo.td
+++ lib/Target/NVPTX/NVPTXInstrInfo.td
@@ -547,15 +547,14 @@
// Integer absolute value. NumBits should be one minus the bit width of RC.
// This idiom implements the algorithm at
// http://graphics.stanford.edu/~seander/bithacks.html#IntegerAbs.
-multiclass ABS<RegisterClass RC, int NumBits, string SizeName> {
+multiclass ABS<RegisterClass RC, string SizeName> {
def : NVPTXInst<(outs RC:$dst), (ins RC:$a),
!strconcat("abs", SizeName, " \t$dst, $a;"),
- [(set RC:$dst, (xor (add (sra RC:$a, (i32 NumBits)), RC:$a),
- (sra RC:$a, (i32 NumBits))))]>;
+ [(set RC:$dst, (abs RC:$a))]>;
}
-defm ABS_16 : ABS<Int16Regs, 15, ".s16">;
-defm ABS_32 : ABS<Int32Regs, 31, ".s32">;
-defm ABS_64 : ABS<Int64Regs, 63, ".s64">;
+defm ABS_16 : ABS<Int16Regs, ".s16">;
+defm ABS_32 : ABS<Int32Regs, ".s32">;
+defm ABS_64 : ABS<Int64Regs, ".s64">;
// Integer min/max.
defm SMAX : I3<"max.s", smax>;
Index: lib/Target/NVPTX/NVPTXISelLowering.cpp
===================================================================
--- lib/Target/NVPTX/NVPTXISelLowering.cpp
+++ lib/Target/NVPTX/NVPTXISelLowering.cpp
@@ -490,6 +490,7 @@
setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::i8, Custom);
for (const auto& Ty : {MVT::i16, MVT::i32, MVT::i64}) {
+ setOperationAction(ISD::ABS, Ty, Legal);
setOperationAction(ISD::SMIN, Ty, Legal);
setOperationAction(ISD::SMAX, Ty, Legal);
setOperationAction(ISD::UMIN, Ty, Legal);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32944.98071.patch
Type: text/x-patch
Size: 1695 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170506/c7929501/attachment.bin>
More information about the llvm-commits
mailing list