[llvm] eb197e3 - [Transforms] Add lit test for instcombine on load into vector of overaligned elements.

Jannik Silvanus via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 04:25:55 PST 2023


Author: Jannik Silvanus
Date: 2023-01-23T13:25:39+01:00
New Revision: eb197e3ea670ee0c573d95a0033327a213656357

URL: https://github.com/llvm/llvm-project/commit/eb197e3ea670ee0c573d95a0033327a213656357
DIFF: https://github.com/llvm/llvm-project/commit/eb197e3ea670ee0c573d95a0033327a213656357.diff

LOG: [Transforms] Add lit test for instcombine on load into vector of overaligned elements.

The result is currently broken in two ways:

 - Valid loads are replaced by poison
 - An array-like layout with padding bytes is assumed

This commit serves as precommit for a patch that addresses the first issue.
The second issue will remain a TODO.

Contributors:
    Sebastian Neubauer <sebastian.neubauer at amd.com>

Added: 
    llvm/test/Transforms/InstCombine/load-gep-overalign.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/load-gep-overalign.ll b/llvm/test/Transforms/InstCombine/load-gep-overalign.ll
new file mode 100644
index 0000000000000..afc3feda51561
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/load-gep-overalign.ll
@@ -0,0 +1,75 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt                        -passes=instcombine -S %s | FileCheck %s --check-prefix=NATURAL
+; RUN: opt --data-layout="i16:32" -passes=instcombine -S %s | FileCheck %s --check-prefix=OVERALIGNED
+
+; The data layouts are little endian, so @foo is 0x0123456789ABCDEF in memory.
+ at foo = constant <4 x i16> <i16 u0x2301, i16 u0x6745, i16 u0xAB89, i16 u0xEFCD>, align 8
+
+declare void @report(i64 %index, i8 %val)
+
+define void @test_vector_load_i8() {
+; Access and report each individual byte in @foo.
+; OVERALIGNED and NATURAL should have the same result, because the layout of vectors ignores
+; element type alignment, and thus the representation of @foo is the same in both cases.
+;
+; TODO: The OVERALIGNED result is incorrect.
+; First, for nonzero even indices, the valid load is replaced by poison.
+; Second, the remaining bytes at indices >= 2 are also incorrect, as apparently padding bytes
+; are assumed as they would appear in an array. In vectors, there is no padding.
+;
+; NATURAL-LABEL: @test_vector_load_i8(
+; NATURAL-NEXT:    call void @report(i64 0, i8 1)
+; NATURAL-NEXT:    call void @report(i64 1, i8 35)
+; NATURAL-NEXT:    call void @report(i64 2, i8 69)
+; NATURAL-NEXT:    call void @report(i64 3, i8 103)
+; NATURAL-NEXT:    call void @report(i64 4, i8 -119)
+; NATURAL-NEXT:    call void @report(i64 5, i8 -85)
+; NATURAL-NEXT:    call void @report(i64 6, i8 -51)
+; NATURAL-NEXT:    call void @report(i64 7, i8 -17)
+; NATURAL-NEXT:    ret void
+;
+; OVERALIGNED-LABEL: @test_vector_load_i8(
+; OVERALIGNED-NEXT:    call void @report(i64 0, i8 1)
+; OVERALIGNED-NEXT:    call void @report(i64 1, i8 35)
+; OVERALIGNED-NEXT:    call void @report(i64 2, i8 poison)
+; OVERALIGNED-NEXT:    call void @report(i64 3, i8 0)
+; OVERALIGNED-NEXT:    call void @report(i64 4, i8 poison)
+; OVERALIGNED-NEXT:    call void @report(i64 5, i8 103)
+; OVERALIGNED-NEXT:    call void @report(i64 6, i8 poison)
+; OVERALIGNED-NEXT:    call void @report(i64 7, i8 0)
+; OVERALIGNED-NEXT:    ret void
+;
+  %ptr0 = getelementptr i8, ptr @foo, i64 0
+  %res0 = load i8, ptr %ptr0, align 1
+  call void @report(i64 0, i8 %res0)
+
+  %ptr1 = getelementptr i8, ptr @foo, i64 1
+  %res1 = load i8, ptr %ptr1, align 1
+  call void @report(i64 1, i8 %res1)
+
+  %ptr2 = getelementptr i8, ptr @foo, i64 2
+  %res2 = load i8, ptr %ptr2, align 1
+  call void @report(i64 2, i8 %res2)
+
+  %ptr3 = getelementptr i8, ptr @foo, i64 3
+  %res3 = load i8, ptr %ptr3, align 1
+  call void @report(i64 3, i8 %res3)
+
+  %ptr4 = getelementptr i8, ptr @foo, i64 4
+  %res4 = load i8, ptr %ptr4, align 1
+  call void @report(i64 4, i8 %res4)
+
+  %ptr5 = getelementptr i8, ptr @foo, i64 5
+  %res5 = load i8, ptr %ptr5, align 1
+  call void @report(i64 5, i8 %res5)
+
+  %ptr6 = getelementptr i8, ptr @foo, i64 6
+  %res6 = load i8, ptr %ptr6, align 1
+  call void @report(i64 6, i8 %res6)
+
+  %ptr7 = getelementptr i8, ptr @foo, i64 7
+  %res7 = load i8, ptr %ptr7, align 1
+  call void @report(i64 7, i8 %res7)
+
+  ret void
+}


        


More information about the llvm-commits mailing list