Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bc0a819

Browse files
nikicc-rhodes
authored andcommitted
[AggressiveInstCombine] Create zext during store merge (#181125)
The top extracted value can include shifted-in zero bits. In that case we should emit a zext before the new store. Fixes #181117. (cherry picked from commit 4167b28)
1 parent 74d4950 commit bc0a819

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ static bool mergeConsecutivePartStores(ArrayRef<PartStore> Parts,
911911
Value *Val = First.Val;
912912
if (First.ValOffset != 0)
913913
Val = Builder.CreateLShr(Val, First.ValOffset);
914-
Val = Builder.CreateTrunc(Val, NewTy);
914+
Val = Builder.CreateZExtOrTrunc(Val, NewTy);
915915
StoreInst *Store = Builder.CreateAlignedStore(
916916
Val, First.Store->getPointerOperand(), First.Store->getAlign());
917917

llvm/test/Transforms/AggressiveInstCombine/X86/store-merge.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,23 @@ define void @test_store_same_parts_twice(i32 %x, ptr %p) {
881881
ret void
882882
}
883883

884+
; A case where the resulting store requires a zext.
885+
define void @test_zext_store(i56 %arg, ptr %p) {
886+
; CHECK-LABEL: define void @test_zext_store(
887+
; CHECK-SAME: i56 [[ARG:%.*]], ptr [[P:%.*]]) {
888+
; CHECK-NEXT: [[TMP1:%.*]] = zext i56 [[ARG]] to i64
889+
; CHECK-NEXT: store i64 [[TMP1]], ptr [[P]], align 4
890+
; CHECK-NEXT: ret void
891+
;
892+
%lo = trunc i56 %arg to i32
893+
store i32 %lo, ptr %p, align 4
894+
%shr = lshr i56 %arg, 32
895+
%hi = trunc i56 %shr to i32
896+
%p.4 = getelementptr i8, ptr %p, i64 4
897+
store i32 %hi, ptr %p.4, align 4
898+
ret void
899+
}
900+
884901
!0 = !{!1}
885902
!1 = !{!1, !2}
886903
!2 = !{!2}

0 commit comments

Comments
 (0)