[PATCH] D144184: [InstSimplify] fold LoadInst for uniformaly initialized constant global variables
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 20 00:44:16 PST 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa4d6c7dd99cb: [InstSimplify] Fold LoadInst for uniform constant global variables (authored by khei4, committed by nikic).
Changed prior to commit:
https://reviews.llvm.org/D144184?vs=498708&id=498750#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144184/new/
https://reviews.llvm.org/D144184
Files:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/load.ll
Index: llvm/test/Transforms/InstSimplify/load.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/load.ll
+++ llvm/test/Transforms/InstSimplify/load.ll
@@ -48,9 +48,7 @@
define i32 @load_gep_const_zero_array(i64 %idx) {
; CHECK-LABEL: @load_gep_const_zero_array(
-; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [4 x i32], ptr @constzeroarray, i64 0, i64 [[IDX:%.*]]
-; CHECK-NEXT: [[LOAD:%.*]] = load i32, ptr [[GEP]], align 4
-; CHECK-NEXT: ret i32 [[LOAD]]
+; CHECK-NEXT: ret i32 0
;
%gep = getelementptr inbounds [4 x i32], ptr @constzeroarray, i64 0, i64 %idx
%load = load i32, ptr %gep
@@ -59,10 +57,7 @@
define i8 @load_i8_multi_gep_const_zero_array(i64 %idx1, i64 %idx2) {
; CHECK-LABEL: @load_i8_multi_gep_const_zero_array(
-; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i8, ptr @constzeroarray, i64 [[IDX1:%.*]]
-; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[GEP1]], i64 [[IDX2:%.*]]
-; CHECK-NEXT: [[LOAD:%.*]] = load i8, ptr [[GEP]], align 1
-; CHECK-NEXT: ret i8 [[LOAD]]
+; CHECK-NEXT: ret i8 0
;
%gep1 = getelementptr inbounds i8, ptr @constzeroarray, i64 %idx1
%gep = getelementptr inbounds i8, ptr %gep1, i64 %idx2
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -6586,6 +6586,12 @@
if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer())
return nullptr;
+ // If GlobalVariable's initializer is uniform, then return the constant
+ // regardless of its offset.
+ if (Constant *C =
+ ConstantFoldLoadFromUniformValue(GV->getInitializer(), LI->getType()))
+ return C;
+
// Try to convert operand into a constant by stripping offsets while looking
// through invariant.group intrinsics.
APInt Offset(Q.DL.getIndexTypeSizeInBits(PtrOp->getType()), 0);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144184.498750.patch
Type: text/x-patch
Size: 2001 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230220/a068f5cb/attachment.bin>
More information about the llvm-commits
mailing list