[llvm] bd2b5ec - [InstCombine] PR58901 - fix bug with swapping GEP of different types
William Huang via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 10 12:24:49 PST 2022
Author: William Huang
Date: 2022-11-10T20:24:41Z
New Revision: bd2b5ec8038e0256dead6f1650318e6c6150e02a
URL: https://github.com/llvm/llvm-project/commit/bd2b5ec8038e0256dead6f1650318e6c6150e02a
DIFF: https://github.com/llvm/llvm-project/commit/bd2b5ec8038e0256dead6f1650318e6c6150e02a.diff
LOG: [InstCombine] PR58901 - fix bug with swapping GEP of different types
Fix https://github.com/llvm/llvm-project/issues/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
Added:
llvm/test/Transforms/InstCombine/pr58901.ll
Modified:
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index ba51ee5c44409..61bac17811326 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2009,6 +2009,7 @@ Instruction *InstCombinerImpl::visitGEPOfGEP(GetElementPtrInst &GEP,
// optimizations below.
if (ShouldCanonicalizeSwap && Src->hasOneUse() &&
Src->getPointerOperandType() == GEP.getPointerOperandType() &&
+ Src->getPointerOperandType() == GEP.getType() &&
Src->getType()->isVectorTy() == GEP.getType()->isVectorTy() &&
!isa<GlobalValue>(Src->getPointerOperand())) {
// When swapping, GEP with all constant indices are more prioritized than
diff --git a/llvm/test/Transforms/InstCombine/pr58901.ll b/llvm/test/Transforms/InstCombine/pr58901.ll
new file mode 100644
index 0000000000000..cab7201857774
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/pr58901.ll
@@ -0,0 +1,23 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+define i32* @f1([6 x i32]* %arg, i64 %arg1) {
+; CHECK-LABEL: @f1(
+; CHECK-NEXT: [[TMP1:%.*]] = getelementptr [6 x i32], [6 x i32]* [[ARG:%.*]], i64 3, i64 [[ARG1:%.*]]
+; CHECK-NEXT: ret i32* [[TMP1]]
+;
+ %1 = getelementptr [6 x i32], [6 x i32]* %arg, i64 3
+ %2 = getelementptr [6 x i32], [6 x i32]* %1, i64 0, i64 %arg1
+ ret i32* %2
+}
+
+define i32* @f2([6 x i32]* %arg, i64 %arg1) {
+; CHECK-LABEL: @f2(
+; CHECK-NEXT: [[TMP1:%.*]] = getelementptr [6 x i32], [6 x i32]* [[ARG:%.*]], i64 3
+; CHECK-NEXT: [[TMP2:%.*]] = getelementptr [6 x i32], [6 x i32]* [[TMP1]], i64 [[ARG1:%.*]], i64 [[ARG1]]
+; CHECK-NEXT: ret i32* [[TMP2]]
+;
+ %1 = getelementptr [6 x i32], [6 x i32]* %arg, i64 3
+ %2 = getelementptr [6 x i32], [6 x i32]* %1, i64 %arg1, i64 %arg1
+ ret i32* %2
+}
More information about the llvm-commits
mailing list