[llvm] [VectorCombine] Fix crash when folding select of bitcast (PR #177183)

Mitch Briles via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 21 11:55:59 PST 2026


================
@@ -0,0 +1,54 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -passes=vector-combine -S %s | FileCheck %s
+
+define i8 @fold_selects_from_bitcast_dominance() {
+; CHECK-LABEL: define i8 @fold_selects_from_bitcast_dominance() {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[COND:%.*]] = icmp eq i8 0, 0
+; CHECK-NEXT:    [[TMP0:%.*]] = select i1 [[COND]], <2 x i32> splat (i32 1), <2 x i32> zeroinitializer
+; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <2 x i32> [[TMP0]] to <8 x i8>
+; CHECK-NEXT:    [[SHIFT:%.*]] = shufflevector <8 x i8> [[TMP1]], <8 x i8> poison, <8 x i32> <i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; CHECK-NEXT:    [[FOLDEXTEXTBINOP:%.*]] = add <8 x i8> [[TMP1]], [[SHIFT]]
+; CHECK-NEXT:    [[SHIFT2:%.*]] = shufflevector <8 x i8> [[TMP1]], <8 x i8> poison, <8 x i32> <i32 2, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; CHECK-NEXT:    [[FOLDEXTEXTBINOP3:%.*]] = add <8 x i8> [[FOLDEXTEXTBINOP]], [[SHIFT2]]
+; CHECK-NEXT:    [[SHIFT5:%.*]] = shufflevector <8 x i8> [[TMP1]], <8 x i8> poison, <8 x i32> <i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; CHECK-NEXT:    [[FOLDEXTEXTBINOP6:%.*]] = add <8 x i8> [[FOLDEXTEXTBINOP3]], [[SHIFT5]]
+; CHECK-NEXT:    [[SHIFT8:%.*]] = shufflevector <8 x i8> [[TMP1]], <8 x i8> poison, <8 x i32> <i32 4, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; CHECK-NEXT:    [[FOLDEXTEXTBINOP9:%.*]] = add <8 x i8> [[FOLDEXTEXTBINOP6]], [[SHIFT8]]
+; CHECK-NEXT:    [[SHIFT11:%.*]] = shufflevector <8 x i8> [[TMP1]], <8 x i8> poison, <8 x i32> <i32 5, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; CHECK-NEXT:    [[FOLDEXTEXTBINOP12:%.*]] = add <8 x i8> [[FOLDEXTEXTBINOP9]], [[SHIFT11]]
+; CHECK-NEXT:    [[SHIFT14:%.*]] = shufflevector <8 x i8> [[TMP1]], <8 x i8> poison, <8 x i32> <i32 6, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; CHECK-NEXT:    [[FOLDEXTEXTBINOP15:%.*]] = add <8 x i8> [[FOLDEXTEXTBINOP12]], [[SHIFT14]]
+; CHECK-NEXT:    [[SHIFT17:%.*]] = shufflevector <8 x i8> [[TMP1]], <8 x i8> poison, <8 x i32> <i32 7, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; CHECK-NEXT:    [[FOLDEXTEXTBINOP18:%.*]] = add <8 x i8> [[FOLDEXTEXTBINOP15]], [[SHIFT17]]
+; CHECK-NEXT:    [[SUM6:%.*]] = extractelement <8 x i8> [[FOLDEXTEXTBINOP18]], i64 0
+; CHECK-NEXT:    ret i8 [[SUM6]]
+;
+entry:
+  %bc = bitcast <2 x i32> splat (i32 1) to <8 x i8>
+  %e0 = extractelement <8 x i8> %bc, i64 0
+  %cond = icmp eq i8 0, 0
----------------
MitchBriles wrote:

Just referring to the `eq i8 0, 0` right? If so, done.

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


More information about the llvm-commits mailing list