While that's conceivable, Merkle-graph systems like Bitcoin are surprisingly resilient. It's been almost 20 years since MD5 was thoroughly broken, but still nobody has published a second preimage attack. For SHA2 and SHA3 nobody has even published a collision attack. And SHA-256 (what Bitcoin uses) is post-quantum-safe (Grover's algorithm still needs 2¹²⁸ time) though AFAIK there isn't yet a post-quantum cryptosystem deployed for signing transactions, which will require a hard fork.
Presumably if quantum computers (or better DLP algorithms on classical computers) start breaking keys, that will become a priority.
So I think there's an excellent chance that even if the math is solved Bitcoins will retain their value. Perhaps even without many of them getting stolen in the process. This is a big difference from many other uses of cryptography; if someone breaks IDEA 20 years from now, they can decrypt your PGP messages from the 20th century, and there's nothing you can do now to prevent that.
We still don't know if P = NP. You seem peculiarly certain it is, which is odd given that most of the people who study the topic strongly suspect otherwise. They could of course be wrong, but what makes you so sure?
Assuming P != NP we still don't have any proof that sha-2 etc can't be reversed (obviously there is a loss of data). It's implausible for now but someday I guarantee we will have the math that makes it trivial. It does not require P = NP.
That is not necessarily how this works. The only thing required to happen is that a super-majority of the miners running the bitcoin software voluntarily update to a new version. This is how changes have been done to BTC before.