Files
clang-p2996/llvm/test/CodeGen/X86/pr64589.ll
Björn Pettersson 2b78303e3f [DAGCombiner] Freeze maybe poison operands when folding select to logic (#84924)
Just like for regular IR we need to treat SELECT as conditionally
blocking poison in SelectionDAG. So (unless the condition itself is
poison) the result is only poison if the selected true/false value is
poison.
Thus, when doing DAG combines that turn SELECT into arithmetic/logical
operations (e.g. AND/OR) we need to make sure that the new operations
aren't more poisonous. One way to do that is to use FREEZE to make
sure the operands aren't posion.

This patch aims at fixing the kind of miscompiles reported in
  https://github.com/llvm/llvm-project/issues/84653
and
  https://github.com/llvm/llvm-project/issues/85190

Solution is to make sure that we insert FREEZE, if needed to make
the fold sound, when using the foldBoolSelectToLogic and
foldVSelectToSignBitSplatMask DAG combines.
2024-07-22 17:19:46 +02:00

26 lines
859 B
LLVM

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
; RUN: llc -mtriple=x86_64-- < %s | FileCheck %s
; It's not possible to directly or the two loads together, because this might
; propagate a poison value from the second load (which has !range but not
; !noundef).
define i8 @test(ptr %p) {
; CHECK-LABEL: test:
; CHECK: # %bb.0:
; CHECK-NEXT: movzbl 1(%rdi), %eax
; CHECK-NEXT: orb (%rdi), %al
; CHECK-NEXT: setne %al
; CHECK-NEXT: addb %al, %al
; CHECK-NEXT: retq
%v1 = load i8, ptr %p, align 4, !range !0, !noundef !{}
%cmp1 = icmp ne i8 %v1, 0
%p2 = getelementptr inbounds i8, ptr %p, i64 1
%v2 = load i8, ptr %p2, align 1, !range !0
%cmp2 = icmp ne i8 %v2, 0
%or = select i1 %cmp1, i1 true, i1 %cmp2
%res = select i1 %or, i8 2, i8 0
ret i8 %res
}
!0 = !{i8 0, i8 2}