Hi,
Segher Boessenkool <seg...@kernel.crashing.org> writes: > Hi! > > On Wed, Jun 14, 2023 at 05:18:15PM +0800, Xi Ruoyao wrote: >> The generic issue here is to fix (not "papering over") the signed >> overflow, we need to perform the addition in a target machine mode. We >> may always use Pmode (IIRC const_anchor was introduced for optimizing >> some constant addresses), but can we do better? > > The main issue is that the machine description generated target code to > compute some constants, but the sanitizer treats it as if it was user > code that might do wrong things. > >> Should we try addition in both DImode and SImode for a 64-bit capable >> machine? > > Why? At least on PowerPC there is only one insn, and it is 64 bits. > The SImode version just ignores all bits other than the low 32 bits, in > both inputs and output. > >> Or should we even try more operations than addition (for eg bit >> operations like xor or shift)? Doing so will need to create a new >> target hook for const anchoring, this is the "complete rework" I meant. > Yeap! This would be a different implementation than the current const_anchor in cse.cc. In postreload.cc, there is another implementation: "reload_cse_move2add" which checks all 'add's instructions from the target. But both implementations have pros and cons. Using gcc source code as a benchmark, analyzing the relations between constants (focusing on those constants in the same function or the same basic block). IIRC, 'add's can cover most of the relations. Small part of constants can be built via other operations(e.g. shift, and, neg ,...). There may be still some benchmarks that hit other operations in the hot path. Indeed, the const_anchor feature could be enhanced to cover more cases. BR, Jeff (Jiufu Guo) > This might make const anchor useful for way more targets maybe, > including rs6000, yes :-) > > > Segher