Skip to content

Commit 03d8831

Browse files
authored
[InstCombine] Handle constant GEP expr in SimplifyDemandedUseBits (#116794)
Closes #116775.
1 parent bdf00e2 commit 03d8831

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I,
997997
uint64_t MaskedGEPIndex = HighBitsGEPIndex | MaskedLowBitsGEPIndex;
998998

999999
if (MaskedGEPIndex != GEPIndex) {
1000-
auto *GEP = cast<GetElementPtrInst>(II->getArgOperand(0));
1000+
auto *GEP = cast<GEPOperator>(II->getArgOperand(0));
10011001
Builder.SetInsertPoint(I);
10021002
Type *GEPIndexType =
10031003
DL.getIndexType(GEP->getPointerOperand()->getType());

llvm/test/Transforms/InstCombine/ptrmask.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,3 +578,16 @@ define ptr @ptrmask_is_useless_fail1(i64 %i, i64 %m) {
578578
%r = call ptr @llvm.ptrmask.p0.i64(ptr %p0, i64 %m0)
579579
ret ptr %r
580580
}
581+
582+
@GC_arrays = external global { i8, i8, i64 }
583+
584+
define ptr @ptrmask_demandedbits_constantexpr() {
585+
; CHECK-LABEL: define ptr @ptrmask_demandedbits_constantexpr() {
586+
; CHECK-NEXT: entry:
587+
; CHECK-NEXT: [[ALIGNED_RESULT:%.*]] = call align 8 ptr @llvm.ptrmask.p0.i64(ptr nonnull @GC_arrays, i64 -8)
588+
; CHECK-NEXT: ret ptr [[ALIGNED_RESULT]]
589+
;
590+
entry:
591+
%aligned_result = call ptr @llvm.ptrmask.p0.i64(ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 1), i64 -8)
592+
ret ptr %aligned_result
593+
}

0 commit comments

Comments
 (0)