[llvm] [InstCombine] Compare `icmp inttoptr, inttoptr` values directly (PR #107012)
Marina Taylor via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 23 15:14:38 PDT 2024
================
@@ -0,0 +1,99 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+declare void @use_ptr(ptr)
+
+define i1 @inttoptr(i64 %x, i64 %y) {
+; CHECK-LABEL: @inttoptr(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %xptr = inttoptr i64 %x to ptr
+ %yptr = inttoptr i64 %y to ptr
+ %cmp = icmp eq ptr %xptr, %yptr
+ ret i1 %cmp
+}
+
+define i1 @inttoptr_constant(i64 %x) {
+; CHECK-LABEL: @inttoptr_constant(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[X:%.*]], 42
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %xptr = inttoptr i64 %x to ptr
+ %cmp = icmp eq ptr %xptr, inttoptr (i64 42 to ptr)
+ ret i1 %cmp
+}
+
+define <2 x i1> @inttoptr_vector(<2 x i64> %x, <2 x i64> %y) {
+; CHECK-LABEL: @inttoptr_vector(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i64> [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %xptr = inttoptr <2 x i64> %x to <2 x ptr>
+ %yptr = inttoptr <2 x i64> %y to <2 x ptr>
+ %cmp = icmp eq <2 x ptr> %xptr, %yptr
+ ret <2 x i1> %cmp
+}
+
+define <2 x i1> @inttoptr_vector_constant(<2 x i64> %x) {
+; CHECK-LABEL: @inttoptr_vector_constant(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i64> [[X:%.*]], <i64 42, i64 123>
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %xptr = inttoptr <2 x i64> %x to <2 x ptr>
+ %cmp = icmp eq <2 x ptr> %xptr, inttoptr (<2 x i64> <i64 42, i64 123> to <2 x ptr>)
+ ret <2 x i1> %cmp
+}
+
+define i1 @inttoptr_size_mismatch(i200 %x, i9 %y) {
+; CHECK-LABEL: @inttoptr_size_mismatch(
+; CHECK-NEXT: [[TMP1:%.*]] = trunc i200 [[X:%.*]] to i64
+; CHECK-NEXT: [[TMP2:%.*]] = zext i9 [[Y:%.*]] to i64
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[TMP1]], [[TMP2]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %xptr = inttoptr i200 %x to ptr
+ %yptr = inttoptr i9 %y to ptr
+ %cmp = icmp eq ptr %xptr, %yptr
+ ret i1 %cmp
+}
+
+define <2 x i1> @inttoptr_vector_constant_size_mismatch(<2 x i200> %x) {
+; CHECK-LABEL: @inttoptr_vector_constant_size_mismatch(
+; CHECK-NEXT: [[TMP1:%.*]] = trunc <2 x i200> [[X:%.*]] to <2 x i64>
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i64> [[TMP1]], <i64 42, i64 123>
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %xptr = inttoptr <2 x i200> %x to <2 x ptr>
+ %cmp = icmp eq <2 x ptr> %xptr, inttoptr (<2x i9> <i9 42, i9 123> to <2 x ptr>)
+ ret <2 x i1> %cmp
+}
----------------
citymarina wrote:
Fixed, thanks.
https://github.com/llvm/llvm-project/pull/107012
More information about the llvm-commits
mailing list