[PATCH] D98114: [Loads] Forward constant vector store to load of first element
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 3 03:10:56 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb552e16b0b04: [Loads] Forward constant vector store to load of first element (authored by nikic).
Changed prior to commit:
https://reviews.llvm.org/D98114?vs=328763&id=335075#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D98114/new/
https://reviews.llvm.org/D98114
Files:
llvm/lib/Analysis/Loads.cpp
llvm/test/Transforms/InstCombine/load-store-forward.ll
Index: llvm/test/Transforms/InstCombine/load-store-forward.ll
===================================================================
--- llvm/test/Transforms/InstCombine/load-store-forward.ll
+++ llvm/test/Transforms/InstCombine/load-store-forward.ll
@@ -22,8 +22,7 @@
; CHECK-LABEL: @vec_store_load_first(
; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>*
; CHECK-NEXT: store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8
-; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[P]], align 4
-; CHECK-NEXT: ret i32 [[LOAD]]
+; CHECK-NEXT: ret i32 1
;
%p2 = bitcast i32* %p to <2 x i32>*
store <2 x i32> <i32 1, i32 2>, <2 x i32>* %p2
@@ -31,6 +30,19 @@
ret i32 %load
}
+define i32 @vec_store_load_first_constexpr(i32* %p) {
+; CHECK-LABEL: @vec_store_load_first_constexpr(
+; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>*
+; CHECK-NEXT: store <2 x i32> bitcast (i64 ptrtoint (i32 (i32*)* @vec_store_load_first to i64) to <2 x i32>), <2 x i32>* [[P2]], align 8
+; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[P]], align 4
+; CHECK-NEXT: ret i32 [[LOAD]]
+;
+ %p2 = bitcast i32* %p to <2 x i32>*
+ store <2 x i32> bitcast (i64 ptrtoint (i32 (i32*)* @vec_store_load_first to i64) to <2 x i32>), <2 x i32>* %p2, align 8
+ %load = load i32, i32* %p, align 4
+ ret i32 %load
+}
+
define i32 @vec_store_load_second(i32* %p) {
; CHECK-LABEL: @vec_store_load_second(
; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>*
Index: llvm/lib/Analysis/Loads.cpp
===================================================================
--- llvm/lib/Analysis/Loads.cpp
+++ llvm/lib/Analysis/Loads.cpp
@@ -495,12 +495,15 @@
if (!AreEquivalentAddressValues(StorePtr, Ptr))
return nullptr;
+ if (IsLoadCSE)
+ *IsLoadCSE = false;
+
Value *Val = SI->getValueOperand();
- if (CastInst::isBitOrNoopPointerCastable(Val->getType(), AccessTy, DL)) {
- if (IsLoadCSE)
- *IsLoadCSE = false;
+ if (CastInst::isBitOrNoopPointerCastable(Val->getType(), AccessTy, DL))
return Val;
- }
+
+ if (auto *C = dyn_cast<Constant>(Val))
+ return ConstantFoldLoadThroughBitcast(C, AccessTy, DL);
}
return nullptr;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98114.335075.patch
Type: text/x-patch
Size: 2224 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210403/8c0b61b4/attachment.bin>
More information about the llvm-commits
mailing list