[llvm] Add known and demanded bits support for zext nneg (PR #70858)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 31 15:00:00 PDT 2023


================
@@ -414,7 +414,10 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
     if (SimplifyDemandedBits(I, 0, InputDemandedMask, InputKnown, Depth + 1))
----------------
nikic wrote:

This is my bad, but let's fix it while we're here: You need to `I->dropPoisonGeneratingFlags()` if SimplifyDemandedBits() succeeds. The nneg flag may no longer be valid after demanded bits simplification.

It took me a while to come up with an example that doesn't get optimized away for other reasons, but I think this demonstrates the currently existing miscompile: https://llvm.godbolt.org/z/9YGME5rs3 The and is what ensures the nneg property, and it gets dropped.

https://github.com/llvm/llvm-project/pull/70858


More information about the llvm-commits mailing list