[llvm] [BOLT] Avoid reference updates for non-JT symbol operands (PR #88838)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 16 20:22:56 PDT 2024
linsinan1995 wrote:
> Thank you for the fix. How did you discover the problem?
Hi @maksfb , I found this problem in an internal testsuite built with clang/llvm toolchain. I did some investigation and saw that some SCEV-based optimizations like loop-reduce and slsr in LLVM can generate this kind of pattern.
LLVM IR log:
```
define dso_local i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
...
br label %5
5: ; preds = %5, %2
%6 = phi i64 [ 0, %2 ], [ %62, %5 ]
%7 = phi i32 [ %4, %2 ], [ %61, %5 ]
...
%36 = getelementptr inbounds [8 x [2 x i8]], ptr @c, i64 0, i64 %6, i64 1
%37 = load i8, ptr %36, align 1, !tbaa !8
%38 = sext i8 %37 to i32
...
%50 = ashr i32 %49, 8
%62 = add nuw nsw i64 %6, 1
%63 = icmp eq i64 %62, 8
br i1 %63, label %64, label %5, !llvm.loop !9
*** IR Dump After Loop Strength Reduction (loop-reduce) ***
; Preheader:
...
br label %5
; Loop:
5: ; preds = %5, %2
%6 = phi i64 [ %64, %5 ], [ -16, %2 ]
...
%37 = getelementptr i8, ptr @c, i64 %6
%38 = getelementptr i8, ptr %37, i64 17
%39 = load i8, ptr %38, align 1, !tbaa !8
%40 = sext i8 %39 to i32
%41 = xor i32 %35, %40
%42 = sext i32 %41 to i64
```
in this case, llvm optimize `getelementptr inbounds [8 x [2 x i8]], ptr @c, i64 0, i64 %6, i64 1` into two simpler operations, `%37 = getelementptr i8, ptr @c, i64 %6` and `getelementptr i8, ptr %37, i64 17`.
after removing PHI
```
%7:gr64 = MOV64ri32 -16
%0:gr32 = MOV32rm $rip, 1, $noreg, @b, $noreg :: (dereferenceable load (s32) from @b, !tbaa !4)
%60:gr64 = COPY killed %7:gr64
%61:gr32 = COPY killed %0:gr32
bb.1 (%ir-block.5):
; predecessors: %bb.0, %bb.1
successors: %bb.2(0x04000000), %bb.1(0x7c000000); %bb.2(3.12%), %bb.1(96.88%)
%2:gr32 = COPY killed %61:gr32
%1:gr64 = COPY killed %60:gr64
...
%41:gr32 = MOVSX32rm8 %1:gr64, 1, $noreg, @c + 17, $noreg :: (invariant load (s8) from %ir.38, !tbaa !8)
%42:gr32 = XOR32rr killed %39:gr32(tied-def 0), killed %41:gr32, implicit-def dead $eflags
...
%60:gr64 = COPY killed %4:gr64
%61:gr32 = COPY %3:gr32
JCC_1 %bb.1, 5, implicit killed $eflags
JMP_1 %bb.2
```
Then we have
```
movq $-0x10, %rax
movl c+17(%rax), %edx
```
https://github.com/llvm/llvm-project/pull/88838
More information about the llvm-commits
mailing list