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); 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 { +multiclass ABS { 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; -defm ABS_32 : ABS; -defm ABS_64 : ABS; +defm ABS_16 : ABS; +defm ABS_32 : ABS; +defm ABS_64 : ABS; // Integer min/max. defm SMAX : I3<"max.s", smax>;