https://bugs.llvm.org/show_bug.cgi?id=49778

            Bug ID: 49778
           Summary: [InstCombine] Miscompile of (x & (~(-1 << x))) << x
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedb...@nondot.org
          Reporter: meh...@google.com
                CC: llvm-bugs@lists.llvm.org

This expression is miscompiled in the case where x is zext of a single bit
value. Here's before and after from a single instcombine transform extracted
using debug_counter and fed to Alive:

----------------------------------------
define i32 @src(i1 %x2) {
%0:
  %x13 = zext i1 %x2 to i32
  %_7 = shl i32 4294967295, %x13
  %mask = xor i32 %_7, 4294967295
  %_8 = and i32 %mask, %x13
  %_9 = shl i32 %_8, %x13
  ret i32 %_9
}
=>
define i32 @tgt(i1 %x2) {
%0:
  %x13 = zext i1 %x2 to i32
  %1 = shl i32 %x13, %x13
  %_9 = and i32 %1, 0
  ret i32 %_9
}
Transformation doesn't verify!
ERROR: Value mismatch

Example:
i1 %x2 = #x1 (1)

Source:
i32 %x13 = #x00000001 (1)
i32 %_7 = #xfffffffe (4294967294, -2)
i32 %mask = #x00000001 (1)
i32 %_8 = #x00000001 (1)
i32 %_9 = #x00000002 (2)

Target:
i32 %x13 = #x00000001 (1)
i32 %1 = #x00000002 (2)
i32 %_9 = #x00000000 (0)
Source value: #x00000002 (2)
Target value: #x00000000 (0)


I suspect the problematic transform is this one:

https://github.com/llvm/llvm-project/blob/c06a8f9caa51c7ea71dac716e0a35f5e343e4546/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp#L168

Looks like maybe(?) NewMask is incorrectly being computed as zero:

https://github.com/llvm/llvm-project/blob/c06a8f9caa51c7ea71dac716e0a35f5e343e4546/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp#L317

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to