[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:20:56 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:
IIUC this gep is indexing into the outermost array, and then the gep below is indexing into the innermost.
So the address of the store could be seen as `%f + (2 * %add) + %add`
But with this patch it looks like we would get `%f + (2 * %add)` instead.
See https://godbolt.org/z/7h75zesM9
https://github.com/llvm/llvm-project/pull/71058
More information about the llvm-commits
mailing list