[llvm] a357137 - [InstCombine] Add test for #97053 (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 3 02:05:41 PDT 2024
Author: Nikita Popov
Date: 2024-07-03T11:05:32+02:00
New Revision: a3571376ad9555de07e4d8f74f92de1eaa4c486e
URL: https://github.com/llvm/llvm-project/commit/a3571376ad9555de07e4d8f74f92de1eaa4c486e
DIFF: https://github.com/llvm/llvm-project/commit/a3571376ad9555de07e4d8f74f92de1eaa4c486e.diff
LOG: [InstCombine] Add test for #97053 (NFC)
Added:
Modified:
llvm/test/Transforms/InstCombine/scalarization.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/scalarization.ll b/llvm/test/Transforms/InstCombine/scalarization.ll
index 7e645ef7e883e..781b5bfb7d6ff 100644
--- a/llvm/test/Transforms/InstCombine/scalarization.ll
+++ b/llvm/test/Transforms/InstCombine/scalarization.ll
@@ -156,6 +156,35 @@ define i8 @extract_element_binop_splat_variable_index(<4 x i8> %x, i32 %y) {
ret i8 %r
}
+; We cannot move the extractelement before the sdiv here, because %z may be
+; out of range, making the divisor poison and resulting in immediate UB.
+; FIXME: This is a miscompile.
+define i8 @extract_element_binop_splat_variable_index_may_trap(<4 x i8> %x, <4 x i8> %y, i32 %z) {
+;
+; CHECK-LABEL: @extract_element_binop_splat_variable_index_may_trap(
+; CHECK-NEXT: [[TMP1:%.*]] = extractelement <4 x i8> [[Y:%.*]], i32 [[Z:%.*]]
+; CHECK-NEXT: [[R:%.*]] = sdiv i8 42, [[TMP1]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %b = sdiv <4 x i8> splat (i8 42), %y
+ %r = extractelement <4 x i8> %b, i32 %z
+ ret i8 %r
+}
+
+; Moving the extractelement first is fine here, because the index is known to
+; be valid, so we can't introduce additional poison.
+define i8 @extract_element_binop_constant_index_may_trap(<4 x i8> %x, <4 x i8> %y, i32 %z) {
+;
+; CHECK-LABEL: @extract_element_binop_constant_index_may_trap(
+; CHECK-NEXT: [[TMP1:%.*]] = extractelement <4 x i8> [[Y:%.*]], i64 3
+; CHECK-NEXT: [[R:%.*]] = sdiv i8 42, [[TMP1]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %b = sdiv <4 x i8> splat (i8 42), %y
+ %r = extractelement <4 x i8> %b, i32 3
+ ret i8 %r
+}
+
define i8 @extract_element_binop_splat_with_undef_variable_index(<4 x i8> %x, i32 %y) {
;
; CHECK-LABEL: @extract_element_binop_splat_with_undef_variable_index(
@@ -344,8 +373,8 @@ define i1 @extractelt_vector_fcmp_constrhs_dynidx(<2 x float> %arg, i32 %idx) {
define i1 @extractelt_vector_fcmp_copy_flags(<4 x float> %x) {
; CHECK-LABEL: @extractelt_vector_fcmp_copy_flags(
; CHECK-NEXT: [[TMP1:%.*]] = extractelement <4 x float> [[X:%.*]], i64 2
-; CHECK-NEXT: [[TMP2:%.*]] = fcmp nsz arcp oeq float [[TMP1]], 0.000000e+00
-; CHECK-NEXT: ret i1 [[TMP2]]
+; CHECK-NEXT: [[R:%.*]] = fcmp nsz arcp oeq float [[TMP1]], 0.000000e+00
+; CHECK-NEXT: ret i1 [[R]]
;
%cmp = fcmp nsz arcp oeq <4 x float> %x, zeroinitializer
%r = extractelement <4 x i1> %cmp, i32 2
More information about the llvm-commits
mailing list