From 652b3757c848770885c1dc8f55292b427de1efa2 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Thu, 4 Jun 2020 08:50:42 -0400 Subject: [PATCH] [x86] add test/code comment for chain value use (PR46195); NFC --- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 7 ++++-- llvm/test/CodeGen/X86/load-chain.ll | 31 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 llvm/test/CodeGen/X86/load-chain.ll diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index d960a74..f603a7c 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -1237,8 +1237,11 @@ SDValue DAGCombiner::PromoteIntBinOp(SDValue Op) { SDValue RV = DAG.getNode(ISD::TRUNCATE, DL, VT, DAG.getNode(Opc, DL, PVT, NN0, NN1)); - // We are always replacing N0/N1's use in N and only need - // additional replacements if there are additional uses. + // We are always replacing N0/N1's use in N and only need additional + // replacements if there are additional uses. + // Note: We are checking uses of the *nodes* (SDNode) rather than values + // (SDValue) here because the node may reference multiple values + // (for example, the chain value of a load node). Replace0 &= !N0->hasOneUse(); Replace1 &= (N0 != N1) && !N1->hasOneUse(); diff --git a/llvm/test/CodeGen/X86/load-chain.ll b/llvm/test/CodeGen/X86/load-chain.ll new file mode 100644 index 0000000..cb75cfb --- /dev/null +++ b/llvm/test/CodeGen/X86/load-chain.ll @@ -0,0 +1,31 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s + +; PR46195 - https://bugs.llvm.org/show_bug.cgi?id=46195 +; It is not safe to sink the load after the call. + +define void @translate(i16* %ptr) nounwind { +; CHECK-LABEL: translate: +; CHECK: # %bb.0: +; CHECK-NEXT: pushq %rbp +; CHECK-NEXT: pushq %rbx +; CHECK-NEXT: pushq %rax +; CHECK-NEXT: movq %rdi, %rbx +; CHECK-NEXT: movl $-32707, %ebp # imm = 0x803D +; CHECK-NEXT: andl (%rdi), %ebp +; CHECK-NEXT: callq maybe_mutate +; CHECK-NEXT: orl $514, %ebp # imm = 0x202 +; CHECK-NEXT: movw %bp, (%rbx) +; CHECK-NEXT: addq $8, %rsp +; CHECK-NEXT: popq %rbx +; CHECK-NEXT: popq %rbp +; CHECK-NEXT: retq + %i0 = load i16, i16* %ptr, align 4 + call void @maybe_mutate(i16* %ptr) + %i1 = and i16 %i0, -32707 + %i2 = or i16 %i1, 514 + store i16 %i2, i16* %ptr, align 4 + ret void +} + +declare void @maybe_mutate(i16*) -- 2.7.4