[llvm] [CodeGenPrepare] Replace deleted sext instr with the promoted value. (PR #71058)

Björn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 2 06:56:46 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
----------------
bjope wrote:

Ok, so it constant folds the add in the second gep, but not in the sext/mul.

> 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)?

That sounds good to me! I think it makes it a bit more clear what happens to the second gep here.

https://github.com/llvm/llvm-project/pull/71058


More information about the llvm-commits mailing list