[PATCH] D137752: [InstCombine] PR58901 - fix bug with swapping GEP of different types

William Junda Huang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 10 12:24:56 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGbd2b5ec8038e: [InstCombine] PR58901 - fix bug with swapping GEP of different types (authored by huangjd).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137752/new/

https://reviews.llvm.org/D137752

Files:
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/pr58901.ll


Index: llvm/test/Transforms/InstCombine/pr58901.ll
===================================================================
--- /dev/null
+++ 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
+}
Index: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2009,6 +2009,7 @@
   // 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137752.474592.patch
Type: text/x-patch
Size: 1817 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221110/90f607c0/attachment.bin>


More information about the llvm-commits mailing list