From 01d1787830cb3c3212cdbe7c019b92560f4607b1 Mon Sep 17 00:00:00 2001 From: James Y Knight Date: Sat, 9 May 2015 03:13:37 +0000 Subject: [PATCH] Fix MergeConsecutiveStore for non-byte-sized memory accesses. The bug showed up as a compile-time assertion failure: Assertion `NumBits >= MIN_INT_BITS && "bitwidth too small"' failed when building msan tests on x86-64. Prior to r236850, this bug was masked due to a bogus alignment check, which also accidentally rejected non-byte-sized accesses. Afterwards, an invalid ElementSizeBytes == 0 got further into the function, and triggered the assertion failure. It would probably be a good idea to allow it to handle merging stores of unusual widths as well, but for now, to un-break it, I'm just making the minimal fix. Differential Revision: http://reviews.llvm.org/D9626 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236927 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 4 ++++ test/CodeGen/X86/merge-consecutive-stores-i1.ll | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/CodeGen/X86/merge-consecutive-stores-i1.ll diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index bd61f0cbd53..3728168e693 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -10673,6 +10673,10 @@ bool DAGCombiner::MergeConsecutiveStores(StoreSDNode* St) { bool NoVectors = DAG.getMachineFunction().getFunction()->hasFnAttribute( Attribute::NoImplicitFloat); + // This function cannot currently deal with non-byte-sized memory sizes. + if (ElementSizeBytes * 8 != MemVT.getSizeInBits()) + return false; + // Don't merge vectors into wider inputs. if (MemVT.isVector() || !MemVT.isSimple()) return false; diff --git a/test/CodeGen/X86/merge-consecutive-stores-i1.ll b/test/CodeGen/X86/merge-consecutive-stores-i1.ll new file mode 100644 index 00000000000..a7f5c214227 --- /dev/null +++ b/test/CodeGen/X86/merge-consecutive-stores-i1.ll @@ -0,0 +1,15 @@ +; RUN: llc -march=x86-64 < %s + +; Ensure that MergeConsecutiveStores doesn't crash when dealing with +; i1 operands. + +%struct.X = type { i1, i1 } + +@b = common global %struct.X zeroinitializer, align 4 + +define void @foo() { +entry: + store i1 0, i1* getelementptr inbounds (%struct.X, %struct.X* @b, i64 0, i32 0), align 4 + store i1 0, i1* getelementptr inbounds (%struct.X, %struct.X* @b, i64 0, i32 1), align 1 + ret void +} -- 2.34.1