[RISCV] Fix miscompile in SExtWRemoval due to early return ignoring other sources
authorPhilip Reames <preames@rivosinc.com>
Wed, 8 Feb 2023 19:35:06 +0000 (11:35 -0800)
committerPhilip Reames <listmail@philipreames.com>
Wed, 8 Feb 2023 19:45:48 +0000 (11:45 -0800)
commitdb6bee5fec0d7fdfc18005c5c5ccd15f1ede945d
treebe45ab0b51e9e35433c81288abd8afdb3aa76325
parent98e7670b64d8b5bbb12432945b476cc9634b6358
[RISCV] Fix miscompile in SExtWRemoval due to early return ignoring other sources

This code is walking back through a worklist of sources. All of the sources need to be sign extending for the result to be true. We had a case which returned rather than continued, which causes a miscompile when another source was not sign extended. The flawed logic was introduced in Dec 22, by change 844430bcc377.

This was recently exposed in a stage2 build of llvm-tablegen when we switched from using llvm::Optional to std::optional. The stars aligned in just the wrong way, and we started actively miscompiling idiomatic optional usage. std::optional<uint32_t> appears to use the top 32 bits of the word on RV64 for its tag.

Differential Revision: https://reviews.llvm.org/D143594
llvm/lib/Target/RISCV/RISCVSExtWRemoval.cpp
llvm/test/CodeGen/RISCV/sextw-removal.ll