[PATCH] D95543: [GVN] Clobber partially aliased loads.
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 22 14:27:08 PDT 2021
nikic added inline comments.
================
Comment at: llvm/test/Transforms/GVN/PRE/rle.ll:736
+; Cross block partial alias case with phi translation.
+; FIXME: Currently we fail to clobber both partially aliased cases of load.
+define i32 @load_load_partial_alias_cross_block_phi_trans(i8* %P) nounwind ssp {
----------------
I believe for phi translation to work you need to have the translated geps in the predecessor. This test case worked for me:
```
define i32 @load_load_partial_alias_cross_block_phi_trans(i8* %P) nounwind {
; LE-LABEL: @load_load_partial_alias_cross_block_phi_trans(
; LE-NEXT: entry:
; LE-NEXT: [[XX:%.*]] = bitcast i8* [[P:%.*]] to i32*
; LE-NEXT: [[X1:%.*]] = load i32, i32* [[XX]], align 4
; LE-NEXT: [[CMP:%.*]] = icmp eq i32 [[X1]], 127
; LE-NEXT: [[TMP0:%.*]] = lshr i32 [[X1]], 16
; LE-NEXT: [[TMP1:%.*]] = trunc i32 [[TMP0]] to i8
; LE-NEXT: [[TMP2:%.*]] = lshr i32 [[X1]], 8
; LE-NEXT: [[TMP3:%.*]] = trunc i32 [[TMP2]] to i8
; LE-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[ELSE:%.*]]
; LE: if:
; LE-NEXT: br label [[JOIN:%.*]]
; LE: else:
; LE-NEXT: br label [[JOIN]]
; LE: join:
; LE-NEXT: [[TMP5:%.*]] = phi i8 [ [[TMP3]], [[IF]] ], [ [[TMP1]], [[ELSE]] ]
; LE-NEXT: [[CONV6:%.*]] = zext i8 [[TMP5]] to i32
; LE-NEXT: ret i32 [[CONV6]]
; LE: if.end:
; LE-NEXT: ret i32 52
;
; BE-LABEL: @load_load_partial_alias_cross_block2(
; BE-NEXT: entry:
; BE-NEXT: [[XX:%.*]] = bitcast i8* [[P:%.*]] to i32*
; BE-NEXT: [[X1:%.*]] = load i32, i32* [[XX]], align 4
; BE-NEXT: [[CMP:%.*]] = icmp eq i32 [[X1]], 127
; BE-NEXT: [[TMP0:%.*]] = lshr i32 [[X1]], 8
; BE-NEXT: [[TMP1:%.*]] = trunc i32 [[TMP0]] to i8
; BE-NEXT: [[TMP2:%.*]] = lshr i32 [[X1]], 16
; BE-NEXT: [[TMP3:%.*]] = trunc i32 [[TMP2]] to i8
; BE-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[ELSE:%.*]]
; BE: if:
; BE-NEXT: br label [[JOIN:%.*]]
; BE: else:
; BE-NEXT: br label [[JOIN]]
; BE: join:
; BE-NEXT: [[TMP5:%.*]] = phi i8 [ [[TMP3]], [[IF]] ], [ [[TMP1]], [[ELSE]] ]
; BE-NEXT: [[CONV6:%.*]] = zext i8 [[TMP5]] to i32
; BE-NEXT: ret i32 [[CONV6]]
; BE: if.end:
; BE-NEXT: ret i32 52
;
entry:
%xx = bitcast i8* %P to i32*
%x1 = load i32, i32* %xx, align 4
%cmp = icmp eq i32 %x1, 127
br i1 %cmp, label %if, label %else
if:
%arrayidx.if = getelementptr inbounds i8, i8* %P, i64 1
br label %join
else:
%arrayidx.else = getelementptr inbounds i8, i8* %P, i64 2
br label %join
join:
%idx = phi i64 [ 1, %if ], [ 2, %else ]
%arrayidx4 = getelementptr inbounds i8, i8* %P, i64 %idx
%tmp5 = load i8, i8* %arrayidx4, align 1
%conv6 = zext i8 %tmp5 to i32
ret i32 %conv6
if.end:
ret i32 52
}
```
I think the actually problematic case probably has something to do with phi translation in loops (where you translate into the same block, but in a different iteration). I'll try to play with that tomorrow, but if I don't find anything let's just land this and see if any miscompiles turn up :)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D95543/new/
https://reviews.llvm.org/D95543
More information about the llvm-commits
mailing list