LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 45447 - Incorrect transformation: (undef u>> a) ^ -1 -> undef >> a, when a != 0
Summary: Incorrect transformation: (undef u>> a) ^ -1 -> undef >> a, when a != 0
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: All All
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords: miscompilation
Depends on:
Blocks: 47948
  Show dependency tree
 
Reported: 2020-04-06 07:05 PDT by Nuno Lopes
Modified: 2020-10-23 18:33 PDT (History)
6 users (show)

See Also:
Fixed By Commit(s): 812970edda36


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nuno Lopes 2020-04-06 07:05:52 PDT
Test: Transforms/InstCombine/vector-xor.ll
Summary: (undef u>> a) ^ -1 always leaves top bits as 1 when a > 0. However 'undef >> a' can leave top bits as 0 or 1, depending on the sign bit of undef.


define <4 x i32> @test_v4i32_not_lshr_nonnegative_const_undef(<4 x i32> %a0) {
  %1 = lshr <4 x i32> { 3, 5, undef, 9 }, %a0
  %2 = xor <4 x i32> { 4294967295, 4294967295, 4294967295, undef }, %1
  ret <4 x i32> %2
}
=>
define <4 x i32> @test_v4i32_not_lshr_nonnegative_const_undef(<4 x i32> %a0) {
  %1 = ashr <4 x i32> { 4294967292, 4294967290, undef, 4294967286 }, %a0
  ret <4 x i32> %1
}
Transformation doesn't verify!
ERROR: Value mismatch

Example:
<4 x i32> %a0 = < #x00000000 (0), #xfffffffe (4294967294, -2), #x0000001f (31), #xfffffffe (4294967294, -2) >

Source:
<4 x i32> %1 = < #x00000003 (3), poison, #x00000000 (0)	[based on undef value], poison >
<4 x i32> %2 = < #xfffffffc (4294967292, -4), poison, #xffffffff (4294967295, -1), poison >

Target:
<4 x i32> %1 = < #xfffffffc (4294967292, -4), poison, #x00000000 (0), poison >
Source value: < #xfffffffc (4294967292, -4), poison, #xffffffff (4294967295, -1), poison >
Target value: < #xfffffffc (4294967292, -4), poison, #x00000000 (0), poison >


https://web.ist.utl.pt/nuno.lopes/alive2/index.php?hash=2009353267698970&test=Transforms%2FInstCombine%2Fvector-xor.ll
Comment 1 Sanjay Patel 2020-04-08 09:22:54 PDT
Patch proposal:
https://reviews.llvm.org/D77739
Comment 2 Sanjay Patel 2020-04-09 05:30:28 PDT
https://reviews.llvm.org/rG812970edda36