This is an archive of the discontinued LLVM Phabricator instance.

[MIPS] Expose the ZERO register as a constant physical register
ClosedPublic

Authored by Carrot on Aug 1 2022, 1:15 PM.

Details

Summary

The ZERO register should be exposed as a constant physical register through the interface TargetRegisterInfo::isConstantPhysReg.

Diff Detail

Event Timeline

Carrot created this revision.Aug 1 2022, 1:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 1:15 PM
Carrot requested review of this revision.Aug 1 2022, 1:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 1:15 PM
MaskRay accepted this revision.Aug 1 2022, 1:38 PM
This revision is now accepted and ready to land.Aug 1 2022, 1:38 PM

It seems not so easy to construct a test. I've tried

declare i64 @llvm.read_register.i64(metadata)
 
define i64 @get_gp() {
  %1 = call i64 @llvm.read_register.i64(metadata !0)
  %2 = call i64 @llvm.read_register.i64(metadata !0)
  %sub = sub i64 %1, %2
  ret i64 %sub
}
 
!0 = !{!"$28"}

which doesn't have benefit in another target which has implemented isConstantPhysReg.

arsenm added a comment.Aug 1 2022, 1:44 PM

It seems not so easy to construct a test. I've tried

declare i64 @llvm.read_register.i64(metadata)
 
define i64 @get_gp() {
  %1 = call i64 @llvm.read_register.i64(metadata !0)
  %2 = call i64 @llvm.read_register.i64(metadata !0)
  %sub = sub i64 %1, %2
  ret i64 %sub
}
 
!0 = !{!"$28"}

which doesn't have benefit in another target which has implemented isConstantPhysReg.

Probably should try for a mir test

Carrot added a comment.Aug 1 2022, 2:18 PM

It seems not so easy to construct a test. I've tried

declare i64 @llvm.read_register.i64(metadata)
 
define i64 @get_gp() {
  %1 = call i64 @llvm.read_register.i64(metadata !0)
  %2 = call i64 @llvm.read_register.i64(metadata !0)
  %sub = sub i64 %1, %2
  ret i64 %sub
}
 
!0 = !{!"$28"}

which doesn't have benefit in another target which has implemented isConstantPhysReg.

Because TargetRegisterInfo::isConstantPhysReg is rarely used directly. People usually call MachineRegisterInfo::isConstantPhysReg which calls TargetRegisterInfo::isConstantPhysReg again. Even TargetRegisterInfo::isConstantPhysReg returns false for Mips::ZERO_64, MachineRegisterInfo::isConstantPhysReg still checks if there is any definition of Mips::ZERO_64, and returns true if there is no def for it. So it's difficult to write a test for it.

I encountered a test case benefited from this patch when I worked on https://reviews.llvm.org/D130919.

This revision was landed with ongoing or failed builds.Aug 2 2022, 10:06 AM
This revision was automatically updated to reflect the committed changes.