"Invented" is a bit of a strong word here: there were "M" and "m3" macro processors before m4. Christopher Stratcheys GPM (General Purpose Macroprocessor, https://academic.oup.com/comjnl/article/8/3/225/336044) was the first macro processor where macros can occur anywhere in the source text - just like in m4. That makes it the first general such program, and not just the macro processor for some specific programming language (like the preprocessor of a macro assembler)