[llvm-branch-commits] [llvm] release/19.x: [InstCombine] Handle constant GEP expr in `SimplifyDemandedUseBits` (#116794) (PR #116814)
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Nov 25 00:37:34 PST 2024
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/116814
>From f9ae37c670d4bcf4713278ac94d2c8991a326f9e Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Tue, 19 Nov 2024 22:17:24 +0800
Subject: [PATCH] [InstCombine] Handle constant GEP expr in
`SimplifyDemandedUseBits` (#116794)
Closes https://github.com/llvm/llvm-project/issues/116775.
(cherry picked from commit 03d8831fa8ef5b7e32172c718b550a454645faea)
---
.../InstCombine/InstCombineSimplifyDemanded.cpp | 2 +-
llvm/test/Transforms/InstCombine/ptrmask.ll | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 8a6ec3076ac621..b9d06b59368508 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -1004,7 +1004,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I,
uint64_t MaskedGEPIndex = HighBitsGEPIndex | MaskedLowBitsGEPIndex;
if (MaskedGEPIndex != GEPIndex) {
- auto *GEP = cast<GetElementPtrInst>(II->getArgOperand(0));
+ auto *GEP = cast<GEPOperator>(II->getArgOperand(0));
Builder.SetInsertPoint(I);
Type *GEPIndexType =
DL.getIndexType(GEP->getPointerOperand()->getType());
diff --git a/llvm/test/Transforms/InstCombine/ptrmask.ll b/llvm/test/Transforms/InstCombine/ptrmask.ll
index 4631b81cd1ce1f..cd998bac3f9f0d 100644
--- a/llvm/test/Transforms/InstCombine/ptrmask.ll
+++ b/llvm/test/Transforms/InstCombine/ptrmask.ll
@@ -578,3 +578,16 @@ define ptr @ptrmask_is_useless_fail1(i64 %i, i64 %m) {
%r = call ptr @llvm.ptrmask.p0.i64(ptr %p0, i64 %m0)
ret ptr %r
}
+
+ at GC_arrays = external global { i8, i8, i64 }
+
+define ptr @ptrmask_demandedbits_constantexpr() {
+; CHECK-LABEL: define ptr @ptrmask_demandedbits_constantexpr() {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[ALIGNED_RESULT:%.*]] = call align 8 ptr @llvm.ptrmask.p0.i64(ptr nonnull @GC_arrays, i64 -8)
+; CHECK-NEXT: ret ptr [[ALIGNED_RESULT]]
+;
+entry:
+ %aligned_result = call ptr @llvm.ptrmask.p0.i64(ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 1), i64 -8)
+ ret ptr %aligned_result
+}
More information about the llvm-branch-commits
mailing list