Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3340,6 +3340,29 @@ bool NVPTXTargetLowering::splitValueIntoRegisterParts(
return false;
}

bool llvm::NVPTXTargetLowering::isTruncateFree(EVT FromVT, EVT ToVT) const {

if (!FromVT.isSimple() || !ToVT.isSimple()) {
return false;
}

return (FromVT.getSimpleVT() == MVT::i64 && ToVT.getSimpleVT() == MVT::i32);
}

bool llvm::NVPTXTargetLowering::isZExtFree(EVT FromVT, EVT ToVT) const {
if (!FromVT.isSimple() || !ToVT.isSimple()) {
return false;
}
return (FromVT.getSimpleVT() == MVT::i32 && ToVT.getSimpleVT() == MVT::i64);
}

bool llvm::NVPTXTargetLowering::isZExtFree(Type *SrcTy, Type *DstTy) const {
if (!SrcTy->isIntegerTy() || !DstTy->isIntegerTy())
return false;
return SrcTy->getPrimitiveSizeInBits() == 32 &&
DstTy->getPrimitiveSizeInBits() == 64;
}

// This creates target external symbol for a function parameter.
// Name of the symbol is composed from its index and the function name.
// Negative index corresponds to special parameter (unsized array) used for
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/NVPTX/NVPTXISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@ class NVPTXTargetLowering : public TargetLowering {
return true;
}

bool isTruncateFree(EVT FromVT, EVT ToVT) const override;
bool isZExtFree(EVT FromVT, EVT ToVT) const override;
bool isZExtFree(Type *SrcTy, Type *DstTy) const override;

private:
const NVPTXSubtarget &STI; // cache the subtarget here
SDValue getParamSymbol(SelectionDAG &DAG, int idx, EVT) const;
Expand Down
17 changes: 17 additions & 0 deletions llvm/test/CodeGen/NVPTX/truncate_zext.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; RUN: llc -march=nvptx64 < %s | FileCheck %s

; Test for truncation from i64 to i32
define i32 @test_trunc_i64_to_i32(i64 %val) {
; CHECK-LABEL: test_trunc_i64_to_i32
; CHECK: trunc
%trunc = trunc i64 %val to i32
ret i32 %trunc
}

; Test for zero-extension from i32 to i64
define i64 @test_zext_i32_to_i64(i32 %val) {
; CHECK-LABEL: test_zext_i32_to_i64
; CHECK: zext
%zext = zext i32 %val to i64
ret i64 %zext
}
Loading