[llvm] [AggressiveInstCombine] Implement store merge optimization (PR #147540)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 17 10:19:48 PDT 2025
dtcxzyw wrote:
```
; bin/opt -passes=aggressive-instcombine,instcombine test.ll -S
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define void @src(ptr %0, ptr %.sroa.0.010) {
%49 = load i16, ptr %.sroa.0.010, align 2
%50 = getelementptr inbounds nuw i8, ptr %.sroa.0.010, i64 2
%51 = load i16, ptr %50, align 4
%.sroa.23.sroa.0.0.insert.ext.i154 = zext i16 %51 to i32
%.sroa.23.0.insert.ext.i156 = zext nneg i32 %.sroa.23.sroa.0.0.insert.ext.i154 to i64
%.sroa.23.0.insert.shift.i157 = shl nuw nsw i64 %.sroa.23.0.insert.ext.i156, 32
%.sroa.15.0.insert.ext.i158 = zext i16 %49 to i64
%.sroa.15.0.insert.shift.i159 = shl nuw nsw i64 %.sroa.15.0.insert.ext.i158, 16
%.sroa.15.0.insert.insert.i160 = or disjoint i64 %.sroa.23.0.insert.shift.i157, %.sroa.15.0.insert.shift.i159
%.sroa.5.0.extract.shift = lshr i64 %.sroa.15.0.insert.insert.i160, 16
%.sroa.5.0.extract.trunc = trunc i64 %.sroa.5.0.extract.shift to i16
%.sroa.6.0.extract.shift = lshr i64 %.sroa.15.0.insert.insert.i160, 32
%.sroa.11.4.extract.trunc = trunc i64 %.sroa.6.0.extract.shift to i16
%125 = getelementptr inbounds nuw i8, ptr %0, i64 2
store i16 %.sroa.5.0.extract.trunc, ptr %125, align 2
%126 = getelementptr inbounds nuw i8, ptr %0, i64 4
store i16 %.sroa.11.4.extract.trunc, ptr %126, align 4
ret void
}
```
Before:
```
define void @src(ptr %0, ptr %.sroa.0.010) {
%2 = load i16, ptr %.sroa.0.010, align 2
%3 = getelementptr inbounds nuw i8, ptr %.sroa.0.010, i64 2
%4 = load i16, ptr %3, align 4
%5 = getelementptr inbounds nuw i8, ptr %0, i64 2
store i16 %2, ptr %5, align 2
%6 = getelementptr inbounds nuw i8, ptr %0, i64 4
store i16 %4, ptr %6, align 4
ret void
}
```
After:
```
define void @src(ptr %0, ptr %.sroa.0.010) {
%2 = load i16, ptr %.sroa.0.010, align 2
%3 = getelementptr inbounds nuw i8, ptr %.sroa.0.010, i64 2
%4 = load i16, ptr %3, align 4
%.sroa.23.0.insert.ext.i156 = zext i16 %4 to i32
%.sroa.23.0.insert.shift.i157 = shl nuw i32 %.sroa.23.0.insert.ext.i156, 16
%.sroa.15.0.insert.ext.i158 = zext i16 %2 to i32
%.sroa.15.0.insert.insert.i160 = or disjoint i32 %.sroa.23.0.insert.shift.i157, %.sroa.15.0.insert.ext.i158
%5 = getelementptr inbounds nuw i8, ptr %0, i64 2
store i32 %.sroa.15.0.insert.insert.i160, ptr %5, align 2
ret void
}
```
https://github.com/llvm/llvm-project/pull/147540
More information about the llvm-commits
mailing list