[llvm] [CodeGenPrepare] Replace deleted sext instr with the promoted value. (PR #71058)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 2 06:39:30 PDT 2023
================
@@ -507,3 +507,25 @@ define i8 @oneArgPromotionBlockSExtZExt(i1 %arg1, ptr %base) {
%res = load i8, ptr %arrayidx
ret i8 %res
}
+
+; Check that we replace the deleted sext with the promoted value.
+; CHECK-LABEL: define void @pr70938(
+; CHECK-SAME: ptr [[F:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[ADD:%.*]] = add nsw i64 0, 0
+; CHECK-NEXT: [[SUNKADDR:%.*]] = mul i64 [[ADD]], 2
+; CHECK-NEXT: [[SUNKADDR1:%.*]] = getelementptr i8, ptr [[F]], i64 [[SUNKADDR]]
+; CHECK-NEXT: store i8 0, ptr [[SUNKADDR1]], align 1
+; CHECK-NEXT: ret void
+define void @pr70938(ptr %f) {
+entry:
+ %add = add nsw i32 0, 0
+ %idxprom3 = sext i32 %add to i64
+ %arrayidx4 = getelementptr [2 x [1 x [2 x i8]]], ptr %f, i64 0, i64 %idxprom3
----------------
dtcxzyw wrote:
IR dumped after `CodeGenPrepare`:
```
define dso_local void @j() local_unnamed_addr #0 {
entry:
%0 = load i8, ptr @h, align 1, !tbaa !5
%tobool.not = icmp eq i8 %0, 0
br i1 %tobool.not, label %for.end15, label %for.cond1.preheader.lr.ph
for.cond1.preheader.lr.ph: ; preds = %entry
%1 = load i32, ptr @b, align 4, !tbaa !8
br label %for.cond1.preheader
for.cond1.preheader: ; preds = %for.cond1.preheader.lr.ph, %if.end
%2 = icmp eq i32 %1, 0
br i1 %2, label %if.end, label %if.then
if.then: ; preds = %for.cond1.preheader
store i32 0, ptr @a, align 4, !tbaa !8
br label %if.end
if.end: ; preds = %if.then, %for.cond1.preheader
%3 = icmp eq i8 %0, 0
store i8 0, ptr getelementptr (i8, ptr @f, i64 3), align 1, !tbaa !5
%inc13 = add nsw i32 0, 1
br i1 %3, label %for.end15.loopexit, label %for.cond1.preheader, !llvm.loop !10
for.end15.loopexit: ; preds = %if.end
store i32 %inc13, ptr @c, align 4, !tbaa !8
br label %for.end15
for.end15: ; preds = %for.end15.loopexit, %entry
ret void
}
```
It is `@f + (2 * %add) + %add`.
Should I modify the regression test (just replacing RHS of `%add = add nsw i32 0, 0` with 1 to match the original C source code)?
https://github.com/llvm/llvm-project/pull/71058
More information about the llvm-commits
mailing list