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 47696 - InstCombine: incorrect select operand simplification with undef
Summary: InstCombine: incorrect select operand simplification with undef
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords: miscompilation
Depends on:
Blocks: 47948
  Show dependency tree
 
Reported: 2020-09-30 10:49 PDT by Nuno Lopes
Modified: 2020-10-23 18:33 PDT (History)
5 users (show)

See Also:
Fixed By Commit(s): 9d1c8c0ba94a273c53829f0800335045e547db88


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nuno Lopes 2020-09-30 10:49:42 PDT
Test: Transforms/InstCombine/select-binop-cmp.ll

Seems to be a regression from https://reviews.llvm.org/D87480
The undef operand in the icmp needs to be fixed to 0 for the transformation to be correct. See here: https://alive2.llvm.org/ce/z/YYhL33


define <2 x i8> @select_xor_icmp_vec_undef(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
  %A = icmp eq <2 x i8> %x, { 0, undef }
  %B = xor <2 x i8> %x, %z
  %C = select <2 x i1> %A, <2 x i8> %B, <2 x i8> %y
  ret <2 x i8> %C
}
=>
define <2 x i8> @select_xor_icmp_vec_undef(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
  %A = icmp eq <2 x i8> %x, { 0, undef }
  %C = select <2 x i1> %A, <2 x i8> %z, <2 x i8> %y
  ret <2 x i8> %C
}
Transformation doesn't verify!
ERROR: Target's return value is more undefined

Example:
<2 x i8> %x = < poison, #x01 (1) >
<2 x i8> %y = < poison, #x00 (0) >
<2 x i8> %z = < poison, #x01 (1) >

Source:
<2 x i1> %A = < poison, any >
<2 x i8> %B = < poison, #x00 (0) >
<2 x i8> %C = < poison, #x00 (0) >

Target:
<2 x i1> %A = < poison, #x1 (1) >
<2 x i8> %C = < poison, #x01 (1) >
Source value: < poison, #x00 (0) >
Target value: < poison, #x01 (1) >


https://web.ist.utl.pt/nuno.lopes/alive2/index.php?hash=1546033e6d866cfc&test=Transforms%2FInstCombine%2Fselect-binop-cmp.ll
Comment 1 Nikita Popov 2020-09-30 11:36:01 PDT
Probably should block this transform if the icmp operand is not guaranteed-not-undef.