[llvm] [InstCombine] fold `sub(zext(ptrtoint), zext(ptrtoint))` (PR #115369)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 14 03:06:29 PST 2024
================
@@ -270,6 +270,36 @@ define i64 @test25(ptr %P, i64 %A){
ret i64 %G
}
+define i64 @zext_ptrtoint_sub_ptrtoint(ptr %p, i32 %offset) {
+; CHECK-LABEL: @zext_ptrtoint_sub_ptrtoint(
+; CHECK-NEXT: %1 = sext i32 %offset to i64
+; CHECK-NEXT: %A = getelementptr bfloat, ptr @Arr, i64 %1
+; CHECK-NEXT: %2 = ptrtoint ptr %A to i64
+; CHECK-NEXT: %C = and i64 %2, 4294967294
+; CHECK-NEXT: %D = sub i64 %C, ptrtoint (ptr @Arr to i64)
+; CHECK-NEXT: ret i64 %D
+ %A = getelementptr bfloat, ptr @Arr, i32 %offset
+ %B = ptrtoint ptr %A to i32
+ %C = zext i32 %B to i64
+ %D = sub i64 %C, ptrtoint (ptr @Arr to i64)
+ ret i64 %D
+}
+
+define i64 @ptrtoint_sub_zext_ptrtoint(ptr %p, i32 %offset) {
+; CHECK-LABEL: @ptrtoint_sub_zext_ptrtoint(
+; CHECK-NEXT: %1 = sext i32 %offset to i64
+; CHECK-NEXT: %A = getelementptr bfloat, ptr @Arr, i64 %1
+; CHECK-NEXT: %2 = ptrtoint ptr %A to i64
+; CHECK-NEXT: %C = and i64 %2, 4294967294
+; CHECK-NEXT: %D = sub i64 ptrtoint (ptr @Arr to i64), %C
+; CHECK-NEXT: ret i64 %D
+ %A = getelementptr bfloat, ptr @Arr, i32 %offset
+ %B = ptrtoint ptr %A to i32
+ %C = zext i32 %B to i64
+ %D = sub i64 ptrtoint (ptr @Arr to i64), %C
+ ret i64 %D
+}
----------------
nikic wrote:
Are these also supposed to be negative tests for wrong bw?
https://github.com/llvm/llvm-project/pull/115369
More information about the llvm-commits
mailing list