[llvm] f104cc3 - [ConstantFold] Don't fold load from non-byte-sized vector
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 17 08:01:57 PST 2022
Author: Nikita Popov
Date: 2022-01-17T17:01:47+01:00
New Revision: f104cc38f45ebbca065e78959c23d09f16b65bd5
URL: https://github.com/llvm/llvm-project/commit/f104cc38f45ebbca065e78959c23d09f16b65bd5
DIFF: https://github.com/llvm/llvm-project/commit/f104cc38f45ebbca065e78959c23d09f16b65bd5.diff
LOG: [ConstantFold] Don't fold load from non-byte-sized vector
Following up on https://github.com/llvm/llvm-project/commit/1470f94d71c544327f76b85c55cb6f7cb43a6cbb#r63981173:
The result here (probably) depends on endianness. Don't bother
trying to handle this exotic case, just bail out.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/test/Transforms/InstCombine/load-store-forward.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index b504d3310f57..253a7243bcf5 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -399,6 +399,12 @@ Constant *llvm::ConstantFoldLoadThroughBitcast(Constant *C, Type *DestTy,
} while (ElemC && DL.getTypeSizeInBits(ElemC->getType()).isZero());
C = ElemC;
} else {
+ // For non-byte-sized vector elements, the first element is not
+ // necessarily located at the vector base address.
+ if (auto *VT = dyn_cast<VectorType>(SrcTy))
+ if (!DL.typeSizeEqualsStoreSize(VT->getElementType()))
+ return nullptr;
+
C = C->getAggregateElement(0u);
}
} while (C);
diff --git a/llvm/test/Transforms/InstCombine/load-store-forward.ll b/llvm/test/Transforms/InstCombine/load-store-forward.ll
index 1f4c49376f9b..c1a01454772f 100644
--- a/llvm/test/Transforms/InstCombine/load-store-forward.ll
+++ b/llvm/test/Transforms/InstCombine/load-store-forward.ll
@@ -47,7 +47,8 @@ define i17 @vec_store_load_first_odd_size(i17* %p) {
; CHECK-LABEL: @vec_store_load_first_odd_size(
; CHECK-NEXT: [[P2:%.*]] = bitcast i17* [[P:%.*]] to <2 x i17>*
; CHECK-NEXT: store <2 x i17> <i17 1, i17 2>, <2 x i17>* [[P2]], align 8
-; CHECK-NEXT: ret i17 1
+; CHECK-NEXT: [[LOAD:%.*]] = load i17, i17* [[P]], align 4
+; CHECK-NEXT: ret i17 [[LOAD]]
;
%p2 = bitcast i17* %p to <2 x i17>*
store <2 x i17> <i17 1, i17 2>, <2 x i17>* %p2
More information about the llvm-commits
mailing list