Skip to content

Commit c6eb67a

Browse files
committed
Remove abs, add a couple more tests
1 parent 8d0d3fc commit c6eb67a

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

llvm/lib/Transforms/Scalar/InferAlignment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ bool inferAlignment(Function &F, AssumptionCache &AC, DominatorTree &DT) {
7474
// Derive the base pointer alignment from the load/store alignment
7575
// and the offset from the base pointer.
7676
Align BasePointerAlign =
77-
commonAlignment(LoadStoreAlign, OffsetFromBase.abs().getLimitedValue());
77+
commonAlignment(LoadStoreAlign, OffsetFromBase.getLimitedValue());
7878

7979
auto [It, Inserted] =
8080
BestBasePointerAligns.try_emplace(PtrOp, BasePointerAlign);
@@ -85,7 +85,7 @@ bool inferAlignment(Function &F, AssumptionCache &AC, DominatorTree &DT) {
8585
// improved base pointer alignment for future iterations.
8686
if (It->second > BasePointerAlign) {
8787
Align BetterLoadStoreAlign =
88-
commonAlignment(It->second, OffsetFromBase.abs().getLimitedValue());
88+
commonAlignment(It->second, OffsetFromBase.getLimitedValue());
8989
return BetterLoadStoreAlign;
9090
}
9191
It->second = BasePointerAlign;

llvm/test/Transforms/InferAlignment/propagate-from-other-load-stores.ll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,31 @@ define void @prop_align_negative_offset_2(ptr %v) {
164164
%loadUnaligned= load float, ptr %v, align 4
165165
ret void
166166
}
167+
168+
define void @prop_align_negative_offset_3(ptr %v) {
169+
; CHECK-LABEL: define void @prop_align_negative_offset_3(
170+
; CHECK-SAME: ptr [[V:%.*]]) {
171+
; CHECK-NEXT: [[LOADALIGNED:%.*]] = load float, ptr [[V]], align 16
172+
; CHECK-NEXT: [[GEPNEGATIVE:%.*]] = getelementptr inbounds nuw i8, ptr [[V]], i64 -8
173+
; CHECK-NEXT: [[LOADUNALIGNED:%.*]] = load float, ptr [[GEPNEGATIVE]], align 8
174+
; CHECK-NEXT: ret void
175+
;
176+
%loadAligned= load float, ptr %v, align 16
177+
%gepNegative = getelementptr inbounds nuw i8, ptr %v, i64 -8
178+
%loadUnaligned = load float, ptr %gepNegative, align 4
179+
ret void
180+
}
181+
182+
define void @prop_align_negative_offset_4(ptr %v) {
183+
; CHECK-LABEL: define void @prop_align_negative_offset_4(
184+
; CHECK-SAME: ptr [[V:%.*]]) {
185+
; CHECK-NEXT: [[LOADALIGNED:%.*]] = load float, ptr [[V]], align 16
186+
; CHECK-NEXT: [[GEPNEGATIVE:%.*]] = getelementptr inbounds nuw i8, ptr [[V]], i64 -20
187+
; CHECK-NEXT: [[LOADUNALIGNED:%.*]] = load float, ptr [[GEPNEGATIVE]], align 4
188+
; CHECK-NEXT: ret void
189+
;
190+
%loadAligned= load float, ptr %v, align 16
191+
%gepNegative = getelementptr inbounds nuw i8, ptr %v, i64 -20
192+
%loadUnaligned = load float, ptr %gepNegative, align 4
193+
ret void
194+
}

0 commit comments

Comments
 (0)