Skip to content
Open
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
16 changes: 12 additions & 4 deletions llvm/lib/Target/NVPTX/NVPTXISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,19 @@ class NVPTXTargetLowering : public TargetLowering {
Instruction *I = nullptr) const override;

bool isTruncateFree(Type *SrcTy, Type *DstTy) const override {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like Hexagon is the only target that does it this way, but seems simpler:

return isTruncateFree(EVT::getEVT(Ty1), EVT::getEVT(Ty2));

// Truncating 64-bit to 32-bit is free in SASS.
if (!SrcTy->isIntegerTy() || !DstTy->isIntegerTy())
if (!(SrcTy->isIntegerTy() && DstTy->isIntegerTy()))
return false;
return SrcTy->getPrimitiveSizeInBits() == 64 &&
DstTy->getPrimitiveSizeInBits() == 32;
if (SrcTy->getPrimitiveSizeInBits() <= DstTy->getPrimitiveSizeInBits())
return false;
Comment on lines -159 to +161
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be valid to call isTruncateFree if either of these conditions were not already met?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so. The second condition is explicitly mentioned in

/// Targets must return false when FromTy <= ToTy.
. Most targets that override this have a check for the first condition as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. What about the check for isScalarInteger? If the vector element sizes meet the criteria for being free won't the eventual expansion be free? Do we ever expect to see non integer types?

Copy link
Contributor Author

@justinfargnoli justinfargnoli May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good point. When expressed in PTX, the vectors become registers and thus do not guarantee contiguousness.

Notes: https://godbolt.org/z/dTo9aGEEb

return DstTy->getPrimitiveSizeInBits() % 32 == 0;
}

bool isTruncateFree(EVT FromVT, EVT ToVT) const override {
if (!(FromVT.isScalarInteger() && ToVT.isScalarInteger()))
return false;
if (FromVT.getSizeInBits() <= ToVT.getSizeInBits())
return false;
Comment on lines +166 to +169
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above.

return ToVT.getSizeInBits() % 32 == 0;
}

EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Ctx,
Expand Down
12 changes: 6 additions & 6 deletions llvm/test/CodeGen/NVPTX/i128-array.ll
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ define [2 x i128] @foo(i64 %a, i32 %b) {
; CHECK-NEXT: .reg .b64 %rd<5>;
; CHECK-EMPTY:
; CHECK-NEXT: // %bb.0:
; CHECK-NEXT: ld.param.u32 %r1, [foo_param_1];
; CHECK-NEXT: ld.param.u64 %rd1, [foo_param_0];
; CHECK-NEXT: shr.s64 %rd2, %rd1, 63;
; CHECK-NEXT: cvt.s64.s32 %rd3, %r1;
; CHECK-NEXT: shr.s64 %rd4, %rd3, 63;
; CHECK-NEXT: st.param.v2.b64 [func_retval0], {%rd1, %rd2};
; CHECK-NEXT: st.param.v2.b64 [func_retval0+16], {%rd3, %rd4};
; CHECK-NEXT: ld.param.s32 %rd2, [foo_param_1];
; CHECK-NEXT: cvt.u32.u64 %r1, %rd2;
; CHECK-NEXT: shr.s64 %rd3, %rd1, 63;
; CHECK-NEXT: shr.s64 %rd4, %rd2, 63;
; CHECK-NEXT: st.param.v2.b64 [func_retval0], {%rd1, %rd3};
; CHECK-NEXT: st.param.v2.b64 [func_retval0+16], {%rd2, %rd4};
; CHECK-NEXT: ret;
%1 = sext i64 %a to i128
%2 = sext i32 %b to i128
Expand Down