From 5994e167a78be1204d127a7835eb2e38245b614b Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Tue, 19 Sep 2017 20:50:05 +0000 Subject: [PATCH] [SystemZ] Fix truncstore + bswap codegen bug SystemZTargetLowering::combineSTORE contains code to transform a combination of STORE + BSWAP into a STRV type instruction. This transformation is correct for regular stores, but not for truncating stores. The routine neglected to check for that case. Fixes a miscompilation of llvm-objcopy with clang, which caused test suite failures in the SystemZ multistage build bot. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313669 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/SystemZ/SystemZISelLowering.cpp | 3 ++- test/CodeGen/SystemZ/bswap-08.ll | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/CodeGen/SystemZ/bswap-08.ll diff --git a/lib/Target/SystemZ/SystemZISelLowering.cpp b/lib/Target/SystemZ/SystemZISelLowering.cpp index 1900a00ef26..9e24a3b9548 100644 --- a/lib/Target/SystemZ/SystemZISelLowering.cpp +++ b/lib/Target/SystemZ/SystemZISelLowering.cpp @@ -5225,7 +5225,8 @@ SDValue SystemZTargetLowering::combineSTORE( } // Combine STORE (BSWAP) into STRVH/STRV/STRVG // See comment in combineBSWAP about volatile accesses. - if (!SN->isVolatile() && + if (!SN->isTruncatingStore() && + !SN->isVolatile() && Op1.getOpcode() == ISD::BSWAP && Op1.getNode()->hasOneUse() && (Op1.getValueType() == MVT::i16 || diff --git a/test/CodeGen/SystemZ/bswap-08.ll b/test/CodeGen/SystemZ/bswap-08.ll new file mode 100644 index 00000000000..f82b09b37b7 --- /dev/null +++ b/test/CodeGen/SystemZ/bswap-08.ll @@ -0,0 +1,17 @@ +; Verify that truncating stores do not use STRV +; +; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s + +declare i64 @llvm.bswap.i64(i64) + +define void @f1(i32* %x, i64* %y) { +; CHECK-LABEL: f1: +; CHECK-NOT: strv +; CHECK: br %r14 + %a = load i64, i64* %y, align 8 + %b = tail call i64 @llvm.bswap.i64(i64 %a) + %conv = trunc i64 %b to i32 + store i32 %conv, i32* %x, align 4 + ret void +} + -- 2.11.0