[llvm] [GlobalIsel] Combine G_ADD and G_SUB with constants (PR #97771)
Thorsten Schütt via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 5 20:57:38 PDT 2024
tschuett wrote:
Firstly, please update the coding style section of the Combiner.rst with the outcome of the discussion.
I don't like the "If the instruction is ***known*** to be a G_CONSTANT ". The I know what I am doing might fail badly.
Warning does not compile:
```
APInt getIConstantFromReg(Register Reg, const MachineRegisterInfoI& MRI) {
return cast<GConstant>(MRI.getVRegDef(Reg))->getAPInt();
}
```
Bugs will make it fail badly. `getIConstantVRegVal` is more verbose, but gives better protection against errors.
In terms of compile-time, the next step is to hoist the oneuse checks into the MIR patterns.
https://github.com/llvm/llvm-project/pull/97771
More information about the llvm-commits
mailing list