Skip to content

Commit 3ca730d

Browse files
committed
[AggressiveInstCombine] Add check for LoadSize2 and remove the power of two check.
1 parent f386a1d commit 3ca730d

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ static bool foldLoadsRecursive(Value *V, LoadOps &LOps, const DataLayout &DL,
682682
return false;
683683

684684
// Support Loadsizes greater or equal to 8bits and only power of 2.
685-
if (LoadSize1 < 8 || !isPowerOf2_64(LoadSize1))
685+
if (LoadSize1 < 8 || LoadSize2 < 8)
686686
return false;
687687

688688
// Alias Analysis to check for stores b/w the loads.

llvm/test/Transforms/AggressiveInstCombine/AArch64/or-load.ll

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,15 +1858,19 @@ define i32 @loadCombine_2consecutive_mixsize_not_power_of_two(ptr %p) {
18581858
}
18591859

18601860
define i32 @loadCombine_2consecutive_mixsize_not_power_of_two2(ptr %p) {
1861-
; ALL-LABEL: @loadCombine_2consecutive_mixsize_not_power_of_two2(
1862-
; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 3
1863-
; ALL-NEXT: [[L1:%.*]] = load i24, ptr [[P]], align 4
1864-
; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
1865-
; ALL-NEXT: [[E1:%.*]] = zext i24 [[L1]] to i32
1866-
; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1867-
; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 24
1868-
; ALL-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
1869-
; ALL-NEXT: ret i32 [[O1]]
1861+
; LE-LABEL: @loadCombine_2consecutive_mixsize_not_power_of_two2(
1862+
; LE-NEXT: [[L1:%.*]] = load i32, ptr [[P:%.*]], align 4
1863+
; LE-NEXT: ret i32 [[L1]]
1864+
;
1865+
; BE-LABEL: @loadCombine_2consecutive_mixsize_not_power_of_two2(
1866+
; BE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 3
1867+
; BE-NEXT: [[L1:%.*]] = load i24, ptr [[P]], align 4
1868+
; BE-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
1869+
; BE-NEXT: [[E1:%.*]] = zext i24 [[L1]] to i32
1870+
; BE-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1871+
; BE-NEXT: [[S2:%.*]] = shl i32 [[E2]], 24
1872+
; BE-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
1873+
; BE-NEXT: ret i32 [[O1]]
18701874
;
18711875
%p1 = getelementptr i8, ptr %p, i32 3
18721876
%l1 = load i24, ptr %p

llvm/test/Transforms/AggressiveInstCombine/X86/or-load.ll

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,15 +1942,19 @@ define i32 @loadCombine_2consecutive_mixsize_not_power_of_two(ptr %p) {
19421942
}
19431943

19441944
define i32 @loadCombine_2consecutive_mixsize_not_power_of_two2(ptr %p) {
1945-
; ALL-LABEL: @loadCombine_2consecutive_mixsize_not_power_of_two2(
1946-
; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 3
1947-
; ALL-NEXT: [[L1:%.*]] = load i24, ptr [[P]], align 4
1948-
; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
1949-
; ALL-NEXT: [[E1:%.*]] = zext i24 [[L1]] to i32
1950-
; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1951-
; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 24
1952-
; ALL-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
1953-
; ALL-NEXT: ret i32 [[O1]]
1945+
; LE-LABEL: @loadCombine_2consecutive_mixsize_not_power_of_two2(
1946+
; LE-NEXT: [[L1:%.*]] = load i32, ptr [[P:%.*]], align 4
1947+
; LE-NEXT: ret i32 [[L1]]
1948+
;
1949+
; BE-LABEL: @loadCombine_2consecutive_mixsize_not_power_of_two2(
1950+
; BE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 3
1951+
; BE-NEXT: [[L1:%.*]] = load i24, ptr [[P]], align 4
1952+
; BE-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
1953+
; BE-NEXT: [[E1:%.*]] = zext i24 [[L1]] to i32
1954+
; BE-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1955+
; BE-NEXT: [[S2:%.*]] = shl i32 [[E2]], 24
1956+
; BE-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
1957+
; BE-NEXT: ret i32 [[O1]]
19541958
;
19551959
%p1 = getelementptr i8, ptr %p, i32 3
19561960
%l1 = load i24, ptr %p

0 commit comments

Comments
 (0)