Index: lib/Transforms/Utils/VNCoercion.cpp =================================================================== --- lib/Transforms/Utils/VNCoercion.cpp +++ lib/Transforms/Utils/VNCoercion.cpp @@ -20,8 +20,13 @@ StoredVal->getType()->isStructTy() || StoredVal->getType()->isArrayTy()) return false; + uint64_t StoreSize = DL.getTypeSizeInBits(StoredVal->getType()); + + if (llvm::alignTo(StoreSize, 8) != StoreSize) + return false; + // The store has to be at least as big as the load. - if (DL.getTypeSizeInBits(StoredVal->getType()) < DL.getTypeSizeInBits(LoadTy)) + if (StoreSize < DL.getTypeSizeInBits(LoadTy)) return false; // Don't coerce non-integral pointers to integers or vice versa. Index: test/Transforms/GVN/load-load-odd-vector.ll =================================================================== --- /dev/null +++ test/Transforms/GVN/load-load-odd-vector.ll @@ -0,0 +1,17 @@ +; RUN: opt -gvn <%s -S -o - | FileCheck %s + +define <7 x i1> @f(<7 x i1>* %a) { +entry: + %vec = load <7 x i1>, <7 x i1>* %a +; CHECK: load <7 x i1>, <7 x i1>* + %0 = getelementptr inbounds <7 x i1>, <7 x i1>* %a, i64 0, i64 0 + %val = load i1, i1* %0, align 2 +; CHECK: load i1, i1* + br i1 %val, label %cond.true, label %cond.false + +cond.true: + ret <7 x i1> %vec + +cond.false: + ret <7 x i1> +} Index: test/Transforms/GVN/pr28879.ll =================================================================== --- /dev/null +++ test/Transforms/GVN/pr28879.ll @@ -0,0 +1,18 @@ +; RUN: opt -gvn <%s -S -o - | FileCheck %s + +define void @f() { +entry: + %a = alloca <7 x i1>, align 2 + store <7 x i1> undef, <7 x i1>* %a, align 2 +; CHECK: store <7 x i1> undef, <7 x i1>* + %0 = getelementptr inbounds <7 x i1>, <7 x i1>* %a, i64 0, i64 0 + %val = load i1, i1* %0, align 2 +; CHECK: load i1, i1* + br i1 %val, label %cond.true, label %cond.false + +cond.true: + ret void + +cond.false: + ret void +}