[llvm] 2e7afb1 - [InstCombine] Move ptrtoaddr tests to InstSimplify (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 20 05:39:51 PDT 2025
Author: Nikita Popov
Date: 2025-10-20T14:39:40+02:00
New Revision: 2e7afb11706e474af6801e63daa8085479cdd08d
URL: https://github.com/llvm/llvm-project/commit/2e7afb11706e474af6801e63daa8085479cdd08d
DIFF: https://github.com/llvm/llvm-project/commit/2e7afb11706e474af6801e63daa8085479cdd08d.diff
LOG: [InstCombine] Move ptrtoaddr tests to InstSimplify (NFC)
All the existing tests test code either in ConstantFolding or
InstSimplify, so move them to use -passes=instsimplify instead of
-passes=instcombine. This makes sure we keep InstSimplify coverage
even if there are subsuming InstCombine folds.
This requires writing some of the constant folding tests in a
different way, as InstSimplify does not try to re-fold already
existing constant expressions.
Added:
llvm/test/Transforms/InstSimplify/ptrtoaddr.ll
Modified:
Removed:
llvm/test/Transforms/InstCombine/ptrtoaddr.ll
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/ptrtoaddr.ll b/llvm/test/Transforms/InstSimplify/ptrtoaddr.ll
similarity index 74%
rename from llvm/test/Transforms/InstCombine/ptrtoaddr.ll
rename to llvm/test/Transforms/InstSimplify/ptrtoaddr.ll
index 1964555673228..03a2d4b57f614 100644
--- a/llvm/test/Transforms/InstCombine/ptrtoaddr.ll
+++ b/llvm/test/Transforms/InstSimplify/ptrtoaddr.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
-; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
; The ptrtoaddr folds are also valid for pointers that have external state.
target datalayout = "pe1:64:64:64:32"
@@ -34,77 +34,95 @@ define i32 @ptrtoaddr_inttoptr() {
; CHECK-LABEL: define i32 @ptrtoaddr_inttoptr() {
; CHECK-NEXT: ret i32 -1
;
- ret i32 ptrtoaddr (ptr addrspace(1) inttoptr (i32 -1 to ptr addrspace(1)) to i32)
+ %toptr = inttoptr i32 -1 to ptr addrspace(1)
+ %toaddr = ptrtoaddr ptr addrspace(1) %toptr to i32
+ ret i32 %toaddr
}
define i32 @ptrtoaddr_inttoptr_
diff _size1() {
; CHECK-LABEL: define i32 @ptrtoaddr_inttoptr_
diff _size1() {
; CHECK-NEXT: ret i32 -1
;
- ret i32 ptrtoaddr (ptr addrspace(1) inttoptr (i64 -1 to ptr addrspace(1)) to i32)
+ %toptr = inttoptr i64 -1 to ptr addrspace(1)
+ %toaddr = ptrtoaddr ptr addrspace(1) %toptr to i32
+ ret i32 %toaddr
}
define i32 @ptrtoaddr_inttoptr_
diff _size2() {
; CHECK-LABEL: define i32 @ptrtoaddr_inttoptr_
diff _size2() {
; CHECK-NEXT: ret i32 65535
;
- ret i32 ptrtoaddr (ptr addrspace(1) inttoptr (i16 -1 to ptr addrspace(1)) to i32)
+ %toptr = inttoptr i16 -1 to ptr addrspace(1)
+ %toaddr = ptrtoaddr ptr addrspace(1) %toptr to i32
+ ret i32 %toaddr
}
define i64 @ptrtoaddr_inttoptr_noas1() {
; CHECK-LABEL: define i64 @ptrtoaddr_inttoptr_noas1() {
; CHECK-NEXT: ret i64 1
;
- ret i64 ptrtoaddr (ptr getelementptr (i8, ptr null, i64 1) to i64)
+ %toptr = getelementptr i8, ptr null, i64 1
+ %toaddr = ptrtoaddr ptr %toptr to i64
+ ret i64 %toaddr
}
define i64 @ptr2addr2_inttoptr_noas2() {
; CHECK-LABEL: define i64 @ptr2addr2_inttoptr_noas2() {
; CHECK-NEXT: ret i64 123
;
- ret i64 ptrtoaddr (ptr inttoptr (i64 123 to ptr) to i64)
+ %toptr = inttoptr i64 123 to ptr
+ %toaddr = ptrtoaddr ptr %toptr to i64
+ ret i64 %toaddr
}
define i64 @ptrtoaddr_inttoptr_noas_
diff _size1() {
; CHECK-LABEL: define i64 @ptrtoaddr_inttoptr_noas_
diff _size1() {
; CHECK-NEXT: ret i64 4294967295
;
- ret i64 ptrtoaddr (ptr inttoptr (i32 -1 to ptr) to i64)
+ %toptr = inttoptr i32 -1 to ptr
+ %toaddr = ptrtoaddr ptr %toptr to i64
+ ret i64 %toaddr
}
define i64 @ptrtoaddr_inttoptr_noas_
diff _size2() {
; CHECK-LABEL: define i64 @ptrtoaddr_inttoptr_noas_
diff _size2() {
; CHECK-NEXT: ret i64 -1
;
- ret i64 ptrtoaddr (ptr inttoptr (i128 -1 to ptr) to i64)
+ %toptr = inttoptr i128 -1 to ptr
+ %toaddr = ptrtoaddr ptr %toptr to i64
+ ret i64 %toaddr
}
define i64 @ptrtoaddr_gep_null() {
; CHECK-LABEL: define i64 @ptrtoaddr_gep_null() {
; CHECK-NEXT: ret i64 42
;
- ret i64 ptrtoaddr (ptr getelementptr (i8, ptr null, i64 42) to i64)
+ %toaddr = ptrtoaddr ptr getelementptr (i8, ptr null, i64 42) to i64
+ ret i64 %toaddr
}
define i32 @ptrtoaddr_gep_null_addrsize() {
; CHECK-LABEL: define i32 @ptrtoaddr_gep_null_addrsize() {
; CHECK-NEXT: ret i32 42
;
- ret i32 ptrtoaddr (ptr addrspace(1) getelementptr (i8, ptr addrspace(1) null, i32 42) to i32)
+ %toaddr = ptrtoaddr ptr addrspace(1) getelementptr (i8, ptr addrspace(1) null, i32 42) to i32
+ ret i32 %toaddr
}
define i64 @ptrtoaddr_gep_sub() {
; CHECK-LABEL: define i64 @ptrtoaddr_gep_sub() {
; CHECK-NEXT: ret i64 sub (i64 ptrtoaddr (ptr @g to i64), i64 ptrtoaddr (ptr @g2 to i64))
;
- ret i64 ptrtoaddr (ptr getelementptr (i8, ptr @g, i64 sub (i64 0, i64 ptrtoaddr (ptr @g2 to i64))) to i64)
+ %toaddr = ptrtoaddr ptr getelementptr (i8, ptr @g, i64 sub (i64 0, i64 ptrtoaddr (ptr @g2 to i64))) to i64
+ ret i64 %toaddr
}
define i32 @ptrtoaddr_gep_sub_addrsize() {
; CHECK-LABEL: define i32 @ptrtoaddr_gep_sub_addrsize() {
; CHECK-NEXT: ret i32 sub (i32 ptrtoaddr (ptr addrspace(1) @g.as1 to i32), i32 ptrtoaddr (ptr addrspace(1) @g2.as1 to i32))
;
- ret i32 ptrtoaddr (ptr addrspace(1) getelementptr (i8, ptr addrspace(1) @g.as1, i32 sub (i32 0, i32 ptrtoaddr (ptr addrspace(1) @g2.as1 to i32))) to i32)
+ %toaddr = ptrtoaddr ptr addrspace(1) getelementptr (i8, ptr addrspace(1) @g.as1, i32 sub (i32 0, i32 ptrtoaddr (ptr addrspace(1) @g2.as1 to i32))) to i32
+ ret i32 %toaddr
}
; Don't fold inttoptr of ptrtoaddr away. inttoptr will pick a previously
@@ -114,28 +132,32 @@ define ptr @inttoptr_of_ptrtoaddr() {
; CHECK-LABEL: define ptr @inttoptr_of_ptrtoaddr() {
; CHECK-NEXT: ret ptr inttoptr (i64 ptrtoaddr (ptr @g to i64) to ptr)
;
- ret ptr inttoptr (i64 ptrtoaddr (ptr @g to i64) to ptr)
+ %toptr = inttoptr i64 ptrtoaddr (ptr @g to i64) to ptr
+ ret ptr %toptr
}
define i64 @ptrtoaddr_sub_consts_unrelated() {
; CHECK-LABEL: define i64 @ptrtoaddr_sub_consts_unrelated() {
; CHECK-NEXT: ret i64 sub (i64 ptrtoaddr (ptr @g to i64), i64 ptrtoaddr (ptr @g2 to i64))
;
- ret i64 sub (i64 ptrtoaddr (ptr @g to i64), i64 ptrtoaddr (ptr @g2 to i64))
+ %sub = sub i64 ptrtoaddr (ptr @g to i64), ptrtoaddr (ptr @g2 to i64)
+ ret i64 %sub
}
define i64 @ptrtoaddr_sub_consts_offset() {
; CHECK-LABEL: define i64 @ptrtoaddr_sub_consts_offset() {
; CHECK-NEXT: ret i64 42
;
- ret i64 sub (i64 ptrtoaddr (ptr getelementptr (i8, ptr @g, i64 42) to i64), i64 ptrtoaddr (ptr @g to i64))
+ %sub = sub i64 ptrtoaddr (ptr getelementptr (i8, ptr @g, i64 42) to i64), ptrtoaddr (ptr @g to i64)
+ ret i64 %sub
}
define i32 @ptrtoaddr_sub_consts_offset_addrsize() {
; CHECK-LABEL: define i32 @ptrtoaddr_sub_consts_offset_addrsize() {
; CHECK-NEXT: ret i32 42
;
- ret i32 sub (i32 ptrtoaddr (ptr addrspace(1) getelementptr (i8, ptr addrspace(1) @g.as1, i32 42) to i32), i32 ptrtoaddr (ptr addrspace(1) @g.as1 to i32))
+ %sub = sub i32 ptrtoaddr (ptr addrspace(1) getelementptr (i8, ptr addrspace(1) @g.as1, i32 42) to i32), ptrtoaddr (ptr addrspace(1) @g.as1 to i32)
+ ret i32 %sub
}
define i64 @ptrtoaddr_sub_known_offset(ptr %p) {
More information about the llvm-commits
mailing list