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);
; 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]]