Skip to content

Revert "[InstCombine] Fold icmp pred (inttoptr X), (inttoptr Y) -> icmp pred X, Y"#78023

Merged
vitalybuka merged 1 commit intomainfrom
revert-77832-fold-icmp-inttoptr
Jan 13, 2024
Merged

Revert "[InstCombine] Fold icmp pred (inttoptr X), (inttoptr Y) -> icmp pred X, Y"#78023
vitalybuka merged 1 commit intomainfrom
revert-77832-fold-icmp-inttoptr

Conversation

@vitalybuka
Copy link
Copy Markdown
Collaborator

@vitalybuka vitalybuka commented Jan 13, 2024

Reverts #77832

To fix https://lab.llvm.org/buildbot/#/builders/236/builds/8673

Also truncation to shorter type looks incorrect.

Issue for tracking #78024 .

@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Jan 13, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Vitaly Buka (vitalybuka)

Changes

Reverts llvm/llvm-project#77832


Full diff: https://github.com/llvm/llvm-project/pull/78023.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp (-9)
  • (modified) llvm/test/Transforms/InstCombine/cast_ptr.ll (-45)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index da94bb1d2a8f36..7c1aff445524de 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -5703,15 +5703,6 @@ Instruction *InstCombinerImpl::foldICmpWithCastOp(ICmpInst &ICmp) {
       return new ICmpInst(ICmp.getPredicate(), Op0Src, NewOp1);
   }
 
-  // Turn icmp pred (inttoptr x), (inttoptr y) into icmp pred x, y
-  if (CastOp0->getOpcode() == Instruction::IntToPtr &&
-      CompatibleSizes(DestTy, SrcTy)) {
-    Value *Op1Src;
-    if (match(ICmp.getOperand(1), m_IntToPtr(m_Value(Op1Src))) &&
-        Op1Src->getType() == SrcTy)
-      return new ICmpInst(ICmp.getPredicate(), Op0Src, Op1Src);
-  }
-
   if (Instruction *R = foldICmpWithTrunc(ICmp))
     return R;
 
diff --git a/llvm/test/Transforms/InstCombine/cast_ptr.ll b/llvm/test/Transforms/InstCombine/cast_ptr.ll
index 8865af0a34a401..5c6c012064e05b 100644
--- a/llvm/test/Transforms/InstCombine/cast_ptr.ll
+++ b/llvm/test/Transforms/InstCombine/cast_ptr.ll
@@ -113,51 +113,6 @@ define i1 @test4(i32 %A) {
   ret i1 %C
 }
 
-define i1 @test4_icmp_with_var(i32 %A1, i32 %A2) {
-; CHECK-LABEL: @test4_icmp_with_var(
-; CHECK-NEXT:    [[C:%.*]] = icmp ugt i32 [[A1:%.*]], [[A2:%.*]]
-; CHECK-NEXT:    ret i1 [[C]]
-;
-  %B1 = inttoptr i32 %A1 to ptr
-  %B2 = inttoptr i32 %A2 to ptr
-  %C = icmp ugt ptr %B1, %B2
-  ret i1 %C
-}
-
-define i1 @test4_cmp_with_nonnull_constant(i32 %A) {
-; CHECK-LABEL: @test4_cmp_with_nonnull_constant(
-; CHECK-NEXT:    [[C:%.*]] = icmp eq i32 [[A:%.*]], 1
-; CHECK-NEXT:    ret i1 [[C]]
-;
-  %B = inttoptr i32 %A to ptr
-  %C = icmp eq ptr %B, inttoptr (i32 1 to ptr)
-  ret i1 %C
-}
-
-define i1 @test4_cmp_eq_0_or_1(i32 %x) {
-; CHECK-LABEL: @test4_cmp_eq_0_or_1(
-; CHECK-NEXT:    [[OR:%.*]] = icmp ult i32 [[X:%.*]], 2
-; CHECK-NEXT:    ret i1 [[OR]]
-;
-  %cast = inttoptr i32 %x to ptr
-  %tobool = icmp eq i32 %x, 0
-  %cmp = icmp eq ptr %cast, inttoptr (i32 1 to ptr)
-  %or = or i1 %tobool, %cmp
-  ret i1 %or
-}
-
-define i1 @test4_icmp_with_var_mismatched_type(i32 %A1, i64 %A2) {
-; CHECK-LABEL: @test4_icmp_with_var_mismatched_type(
-; CHECK-NEXT:    [[TMP1:%.*]] = trunc i64 [[A2:%.*]] to i32
-; CHECK-NEXT:    [[C:%.*]] = icmp ult i32 [[TMP1]], [[A1:%.*]]
-; CHECK-NEXT:    ret i1 [[C]]
-;
-  %B1 = inttoptr i32 %A1 to ptr
-  %B2 = inttoptr i64 %A2 to ptr
-  %C = icmp ugt ptr %B1, %B2
-  ret i1 %C
-}
-
 define i1 @test4_as2(i16 %A) {
 ; CHECK-LABEL: @test4_as2(
 ; CHECK-NEXT:    [[C:%.*]] = icmp eq i16 [[A:%.*]], 0

@vitalybuka vitalybuka requested a review from dtcxzyw January 13, 2024 08:56
@dtcxzyw
Copy link
Copy Markdown
Member

dtcxzyw commented Jan 13, 2024

Bisect is not finished, but it passed after this patch. Sorry of the noise.

Are you sure reverting #78023 will fix the crash?

@vitalybuka
Copy link
Copy Markdown
Collaborator Author

vitalybuka commented Jan 13, 2024

Bisect is not finished, but it passed after this patch. Sorry of the noise.

Are you sure reverting #78023 will fix the crash?

This is bisect in progress, https://lab.llvm.org/buildbot/#/builders/236/builds/8688

at the moment it's on this range with this patch and the rest looks irrelevant.
I will wait for bisect completion.

2aae304 [InstCombine] Fold icmp pred (inttoptr X), (inttoptr Y) -> icmp pred X, Y (#77832)
d199ab4 [LLVM][DWARF] Fix accelerator table switching between CU and TU (#77511)
5417a5f [mlir][ArmSME] Add rudimentary support for tile spills to the stack (#76086)
8751bbe [libc++] Deprecate the _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS macro (#77692)
dec908a [mlir][Transforms] GreedyPatternRewriteDriver: log successful folding (#77796)

Copy link
Copy Markdown
Member

@dtcxzyw dtcxzyw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first bad commit: [2aae304] [InstCombine] Fold icmp pred (inttoptr X), (inttoptr Y) -> icmp pred X, Y (#77832)

@vitalybuka vitalybuka merged commit 253d2f9 into main Jan 13, 2024
@vitalybuka vitalybuka deleted the revert-77832-fold-icmp-inttoptr branch January 13, 2024 19:15
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
…cmp pred X, Y`" (llvm#78023)

Reverts llvm#77832

To fix https://lab.llvm.org/buildbot/#/builders/236/builds/8673

Also truncation to shorter type looks incorrect.

Issue for tracking llvm#78024 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants