[llvm] 3138c59 - [InstCombine] Add more gep index canonicalization tests (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 4 01:20:00 PDT 2024
Author: Nikita Popov
Date: 2024-06-04T10:19:52+02:00
New Revision: 3138c590859ffff5d77f878f3b297960c8842180
URL: https://github.com/llvm/llvm-project/commit/3138c590859ffff5d77f878f3b297960c8842180
DIFF: https://github.com/llvm/llvm-project/commit/3138c590859ffff5d77f878f3b297960c8842180.diff
LOG: [InstCombine] Add more gep index canonicalization tests (NFC)
Flags are already fully preserved for the instruction case,
but lost on constant expressions.
Added:
Modified:
llvm/test/Transforms/InstCombine/getelementptr.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/getelementptr.ll b/llvm/test/Transforms/InstCombine/getelementptr.ll
index 627226bc9459c..dc7ecd1f52638 100644
--- a/llvm/test/Transforms/InstCombine/getelementptr.ll
+++ b/llvm/test/Transforms/InstCombine/getelementptr.ll
@@ -389,9 +389,8 @@ define ptr @test15(i64 %X) {
ret ptr %A
}
-
-define ptr @test16(ptr %X, i32 %Idx) {
-; CHECK-LABEL: @test16(
+define ptr @test_index_canon(ptr %X, i32 %Idx) {
+; CHECK-LABEL: @test_index_canon(
; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[IDX:%.*]] to i64
; CHECK-NEXT: [[R:%.*]] = getelementptr i32, ptr [[X:%.*]], i64 [[TMP1]]
; CHECK-NEXT: ret ptr [[R]]
@@ -400,6 +399,39 @@ define ptr @test16(ptr %X, i32 %Idx) {
ret ptr %R
}
+define ptr @test_index_canon_inbounds(ptr %X, i32 %Idx) {
+; CHECK-LABEL: @test_index_canon_inbounds(
+; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[IDX:%.*]] to i64
+; CHECK-NEXT: [[R:%.*]] = getelementptr inbounds i32, ptr [[X:%.*]], i64 [[TMP1]]
+; CHECK-NEXT: ret ptr [[R]]
+;
+ %R = getelementptr inbounds i32, ptr %X, i32 %Idx
+ ret ptr %R
+}
+
+define ptr @test_index_canon_nusw_nuw(ptr %X, i32 %Idx) {
+; CHECK-LABEL: @test_index_canon_nusw_nuw(
+; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[IDX:%.*]] to i64
+; CHECK-NEXT: [[R:%.*]] = getelementptr nusw nuw i32, ptr [[X:%.*]], i64 [[TMP1]]
+; CHECK-NEXT: ret ptr [[R]]
+;
+ %R = getelementptr nusw nuw i32, ptr %X, i32 %Idx
+ ret ptr %R
+}
+
+define ptr @test_index_canon_const_expr_inbounds(ptr %X, i32 %Idx) {
+; CHECK-LABEL: @test_index_canon_const_expr_inbounds(
+; CHECK-NEXT: ret ptr getelementptr inbounds (i8, ptr @Global, i64 123)
+;
+ ret ptr getelementptr inbounds (i8, ptr @Global, i32 123)
+}
+
+define ptr @test_index_canon_const_expr_nuw_nusw(ptr %X, i32 %Idx) {
+; CHECK-LABEL: @test_index_canon_const_expr_nuw_nusw(
+; CHECK-NEXT: ret ptr getelementptr (i8, ptr @Global, i64 123)
+;
+ ret ptr getelementptr nusw nuw (i8, ptr @Global, i32 123)
+}
define i1 @test17(ptr %P, i32 %I, i32 %J) {
; CHECK-LABEL: @test17(
More information about the llvm-commits
mailing list