Skip to content

InstCombine miscompilation #114178

@bongjunj

Description

@bongjunj

The following lines are executed:

auto SQDistributive = SQ.getWithInstruction(&I).getWithoutUndef();
Value *L = simplifyBinOp(TopLevelOpcode, A, B, SQDistributive);
Value *R = simplifyBinOp(TopLevelOpcode, A, C, SQDistributive);
// Do "A op B" and "A op C" both simplify?
if (L && R) {
// They do! Return "L op' R".
++NumExpand;
A = Builder.CreateBinOp(InnerOpcode, L, R);
A->takeName(&I);
return A;
}

Alive2 report: https://alive2.llvm.org/ce/z/4Ht3eF

----------------------------------------
define i8 @or_not_and_and_not_and_xor_commute2.2(i8 %a0, i8 %b, i8 %c) {
#0:
  %#1 = sdiv i8 %a0, 10
  %and1 = and i8 %b, %b
  %not1 = xor i8 %and1, 255
  %or1 = or i8 %#1, %not1
  %#2 = sdiv i8 %b, %not1
  %and2 = and i8 %#2, %#1
  %not2 = xor i8 %and2, 255
  %and3 = and i8 %or1, %not2
  ret i8 %and3
}
=>
define i8 @or_not_and_and_not_and_xor_commute2.2(i8 %a0, i8 %b, i8 %c) {
#0:
  %#1 = sdiv i8 %a0, 10
  %not1 = xor i8 %b, 255
  %or1 = or i8 %#1, %not1
  %#2 = sdiv i8 %b, %not1
  %and2 = and i8 %#2, %#1
  %and3 = xor i8 %and2, %or1
  ret i8 %and3
}
Transformation doesn't verify!

ERROR: Value mismatch

Example:
i8 %a0 = undef
i8 %b = #xbb (187, -69)
i8 %c = #x00 (0)	[based on undef value]

Source:
i8 %#1 = #x00 (0)	[based on undef value]
i8 %and1 = #xbb (187, -69)
i8 %not1 = #x44 (68)
i8 %or1 = #x44 (68)
i8 %#2 = #xff (255, -1)
i8 %and2 = #x00 (0)	[based on undef value]
i8 %not2 = #xff (255, -1)
i8 %and3 = #x44 (68)

Target:
i8 %#1 = #x00 (0)
i8 %not1 = #x44 (68)
i8 %or1 = #x44 (68)
i8 %#2 = #xff (255, -1)
i8 %and2 = #xfb (251, -5)
i8 %and3 = #xbf (191, -65)
Source value: #x44 (68)
Target value: #xbf (191, -65)

Summary:
  0 correct transformations
  1 incorrect transformations
  0 failed-to-prove transformations
  0 Alive2 errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    llvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmiscompilation:undefMiscompilation that only occurs with undef values

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions