[llvm] Revert 112e49b38150b8bfdef01434309d1b05204193e4 due to a miscompile (PR #71598)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 8 10:31:04 PST 2023


goldsteinn wrote:

The following seems to be the fix:
```
-        bool CanTransform =
-            IsRotate ||
-            (*ShiftCAmt == (~*AndCMask).popcount() && ShiftOpc == ISD::SHL
-                 ? (~*AndCMask).isMask()
-                 : AndCMask->isMask());
+        bool CanTransform = IsRotate;
+        if (!CanTransform) {
+          // Check that mask and shift compliment eachother
+          CanTransform = *ShiftCAmt == (~*AndCMask).popcount();
+          // Check that we are comparing all bits
+          CanTransform &= (*ShiftCAmt + AndCMask->popcount()) == NumBits;
+          // Check that the and mask is correct for the shift
+          CanTransform &=
+              ShiftOpc == ISD::SHL ? (~*AndCMask).isMask() : AndCMask->isMask();
+        }
```

Will post patch for recommit shortly.

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


More information about the llvm-commits mailing list