Skip to content

Commit 98dda9d

Browse files
clin111huangjd
andauthored
[InstCombine] PR58901 - fix bug with swapping GEP of different types (#7367)
Fix llvm/llvm-project#58901 by adding stricter check whether non-opaque GEP can be swapped. This will not affect GEP swapping optimization in the future since we are switching to opaque GEP Reviewed By: clin1 Differential Revision: https://reviews.llvm.org/D137752 Co-authored-by: William Huang <[email protected]>
1 parent 5b1bce1 commit 98dda9d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,7 @@ Instruction *InstCombinerImpl::visitGEPOfGEP(GetElementPtrInst &GEP,
20092009
// optimizations below.
20102010
if (ShouldCanonicalizeSwap && Src->hasOneUse() &&
20112011
Src->getPointerOperandType() == GEP.getPointerOperandType() &&
2012+
Src->getPointerOperandType() == GEP.getType() &&
20122013
Src->getType()->isVectorTy() == GEP.getType()->isVectorTy() &&
20132014
!isa<GlobalValue>(Src->getPointerOperand())) {
20142015
// When swapping, GEP with all constant indices are more prioritized than
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3+
4+
define i32* @f1([6 x i32]* %arg, i64 %arg1) {
5+
; CHECK-LABEL: @f1(
6+
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr [6 x i32], [6 x i32]* [[ARG:%.*]], i64 3, i64 [[ARG1:%.*]]
7+
; CHECK-NEXT: ret i32* [[TMP1]]
8+
;
9+
%1 = getelementptr [6 x i32], [6 x i32]* %arg, i64 3
10+
%2 = getelementptr [6 x i32], [6 x i32]* %1, i64 0, i64 %arg1
11+
ret i32* %2
12+
}
13+
14+
define i32* @f2([6 x i32]* %arg, i64 %arg1) {
15+
; CHECK-LABEL: @f2(
16+
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr [6 x i32], [6 x i32]* [[ARG:%.*]], i64 3
17+
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr [6 x i32], [6 x i32]* [[TMP1]], i64 [[ARG1:%.*]], i64 [[ARG1]]
18+
; CHECK-NEXT: ret i32* [[TMP2]]
19+
;
20+
%1 = getelementptr [6 x i32], [6 x i32]* %arg, i64 3
21+
%2 = getelementptr [6 x i32], [6 x i32]* %1, i64 %arg1, i64 %arg1
22+
ret i32* %2
23+
}

0 commit comments

Comments
 (0)