mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-10 22:46:25 +00:00
GlobalISel: avoid inserting redundant COPYs for bitcasts.
If the value produced by the bitcast hasn't been referenced yet, we can simply reuse the input register avoiding an unnecessary COPY instruction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278245 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3b54bd1701
commit
6b89c9016c
@ -166,8 +166,11 @@ bool IRTranslator::translateStore(const StoreInst &SI) {
|
||||
|
||||
bool IRTranslator::translateBitCast(const CastInst &CI) {
|
||||
if (LLT{*CI.getDestTy()} == LLT{*CI.getSrcTy()}) {
|
||||
MIRBuilder.buildCopy(getOrCreateVReg(CI),
|
||||
getOrCreateVReg(*CI.getOperand(0)));
|
||||
unsigned &Reg = ValToVReg[&CI];
|
||||
if (Reg)
|
||||
MIRBuilder.buildCopy(Reg, getOrCreateVReg(*CI.getOperand(0)));
|
||||
else
|
||||
Reg = getOrCreateVReg(*CI.getOperand(0));
|
||||
return true;
|
||||
}
|
||||
return translateCast(TargetOpcode::G_BITCAST, CI);
|
||||
|
@ -214,14 +214,33 @@ define i64* @inttoptr(i64 %a) {
|
||||
|
||||
; CHECK-LABEL: name: trivial_bitcast
|
||||
; CHECK: [[ARG1:%[0-9]+]](64) = COPY %x0
|
||||
; CHECK: [[RES:%[0-9]+]](64) = COPY [[ARG1]]
|
||||
; CHECK: %x0 = COPY [[RES]]
|
||||
; CHECK: %x0 = COPY [[ARG1]]
|
||||
; CHECK: RET_ReallyLR implicit %x0
|
||||
define i64* @trivial_bitcast(i8* %a) {
|
||||
%val = bitcast i8* %a to i64*
|
||||
ret i64* %val
|
||||
}
|
||||
|
||||
; CHECK-LABEL: name: trivial_bitcast_with_copy
|
||||
; CHECK: [[A:%[0-9]+]](64) = COPY %x0
|
||||
; CHECK: G_BR unsized %[[CAST:bb\.[0-9]+]]
|
||||
|
||||
; CHECK: [[CAST]]:
|
||||
; CHECK: {{%[0-9]+}}(64) = COPY [[A]]
|
||||
; CHECK: G_BR unsized %[[END:bb\.[0-9]+]]
|
||||
|
||||
; CHECK: [[END]]:
|
||||
define i64* @trivial_bitcast_with_copy(i8* %a) {
|
||||
br label %cast
|
||||
|
||||
end:
|
||||
ret i64* %val
|
||||
|
||||
cast:
|
||||
%val = bitcast i8* %a to i64*
|
||||
br label %end
|
||||
}
|
||||
|
||||
; CHECK-LABEL: name: bitcast
|
||||
; CHECK: [[ARG1:%[0-9]+]](64) = COPY %x0
|
||||
; CHECK: [[RES1:%[0-9]+]](64) = G_BITCAST { <2 x s32>, s64 } [[ARG1]]
|
||||
|
Loading…
x
Reference in New Issue
Block a user