Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ bool X86LegalizerInfo::legalizeCustom(LegalizerHelper &Helper, MachineInstr &MI,
return legalizeSITOFP(MI, MRI, Helper);
case TargetOpcode::G_FPTOSI:
return legalizeFPTOSI(MI, MRI, Helper);
case TargetOpcode::G_BITCAST:
return legalizeBitcast(MI, MRI, Helper);
}
llvm_unreachable("expected switch to return");
}
Expand Down Expand Up @@ -835,6 +837,23 @@ bool X86LegalizerInfo::legalizeNarrowingStore(MachineInstr &MI,
return true;
}

bool X86LegalizerInfo::legalizeBitcast(MachineInstr &MI,
MachineRegisterInfo &MRI,
LegalizerHelper &Helper) const {
MachineIRBuilder &MIRBuilder = Helper.MIRBuilder;
auto [DstReg, DstTy, SrcReg, SrcTy] = MI.getFirst2RegLLTs();
assert(!SrcTy.isVector() && "G_BITCAST does not support vectors yet");
Copy link

Choose a reason for hiding this comment

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

Is it correct to put assert there? It may be better to return false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. It seems like multiple recurring pattern though

assert((SrcTy.getSizeInBits() == 16 || SrcTy.getSizeInBits() == 32 ||

assert((Opc == TargetOpcode::G_STORE || Opc == TargetOpcode::G_LOAD) &&

bool isCopy =
(SrcTy == DstTy) || (SrcTy.getSizeInBits() == DstTy.getSizeInBits());
if (isCopy) {
MIRBuilder.buildCopy(DstReg, SrcReg);
MI.eraseFromParent();
return true;
}
// For Vectors specific bitcasts
return Helper.lowerBitcast(MI) == LegalizerHelper::LegalizeResult::Legalized;
}

bool X86LegalizerInfo::legalizeIntrinsic(LegalizerHelper &Helper,
MachineInstr &MI) const {
return true;
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/X86/GISel/X86LegalizerInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class X86LegalizerInfo : public LegalizerInfo {

bool legalizeFPTOSI(MachineInstr &MI, MachineRegisterInfo &MRI,
LegalizerHelper &Helper) const;
bool legalizeBitcast(MachineInstr &MI, MachineRegisterInfo &MRI,
LegalizerHelper &Helper) const;
};
} // namespace llvm
#endif
19 changes: 19 additions & 0 deletions llvm/test/CodeGen/X86/bitcast.ll
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc < %s -mtriple=i686--
; RUN: llc < %s -mtriple=x86_64--
; RUN: llc < %s -mtriple=x86_64-- -global-isel -global-isel-abort=1 | FileCheck %s -check-prefixes=GISEL
; XRUN: llc < %s -mtriple=i686-- -global-isel -global-isel-abort=1 | FileCheck %s -check-prefixes=GISEL
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i686 run is WIP

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

; PR1033

define i64 @test1(double %t) {
; GISEL-LABEL: test1:
; GISEL: # %bb.0:
; GISEL-NEXT: movq %xmm0, %rax
; GISEL-NEXT: retq
%u = bitcast double %t to i64 ; <i64> [#uses=1]
ret i64 %u
}

define double @test2(i64 %t) {
; GISEL-LABEL: test2:
; GISEL: # %bb.0:
; GISEL-NEXT: movq %rdi, %xmm0
; GISEL-NEXT: retq
%u = bitcast i64 %t to double ; <double> [#uses=1]
ret double %u
}

define i32 @test3(float %t) {
; GISEL-LABEL: test3:
; GISEL: # %bb.0:
; GISEL-NEXT: movd %xmm0, %eax
; GISEL-NEXT: retq
%u = bitcast float %t to i32 ; <i32> [#uses=1]
ret i32 %u
}

define float @test4(i32 %t) {
; GISEL-LABEL: test4:
; GISEL: # %bb.0:
; GISEL-NEXT: movd %edi, %xmm0
; GISEL-NEXT: retq
%u = bitcast i32 %t to float ; <float> [#uses=1]
ret float %u
}
Expand Down
Loading