1; RUN: opt -S -slp-threshold=-6 -slp-vectorizer -instcombine < %s | FileCheck %s 2 3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 4target triple = "x86_64-unknown-linux-gnu" 5 6; These tests ensure that we do not regress due to PR31243. Note that we set 7; the SLP threshold to force vectorization even when not profitable. 8 9; CHECK-LABEL: @PR31243_zext 10; 11; When computing minimum sizes, if we can prove the sign bit is zero, we can 12; zero-extend the roots back to their original sizes. 13; 14; CHECK: %[[OR:.+]] = or <2 x i8> {{.*}}, <i8 1, i8 1> 15; CHECK: %[[E0:.+]] = extractelement <2 x i8> %[[OR]], i32 0 16; CHECK: %[[Z0:.+]] = zext i8 %[[E0]] to i64 17; CHECK: getelementptr inbounds i8, i8* %ptr, i64 %[[Z0]] 18; CHECK: %[[E1:.+]] = extractelement <2 x i8> %[[OR]], i32 1 19; CHECK: %[[Z1:.+]] = zext i8 %[[E1]] to i64 20; CHECK: getelementptr inbounds i8, i8* %ptr, i64 %[[Z1]] 21; 22define i8 @PR31243_zext(i8 %v0, i8 %v1, i8 %v2, i8 %v3, i8* %ptr) { 23entry: 24 %tmp0 = zext i8 %v0 to i32 25 %tmp1 = zext i8 %v1 to i32 26 %tmp2 = or i32 %tmp0, 1 27 %tmp3 = or i32 %tmp1, 1 28 %tmp4 = getelementptr inbounds i8, i8* %ptr, i32 %tmp2 29 %tmp5 = getelementptr inbounds i8, i8* %ptr, i32 %tmp3 30 %tmp6 = load i8, i8* %tmp4 31 %tmp7 = load i8, i8* %tmp5 32 %tmp8 = add i8 %tmp6, %tmp7 33 ret i8 %tmp8 34} 35 36; CHECK-LABEL: @PR31243_sext 37; 38; When computing minimum sizes, if we cannot prove the sign bit is zero, we 39; have to include one extra bit for signedness since we will sign-extend the 40; roots. 41; 42; FIXME: This test is suboptimal since the compuation can be performed in i8. 43; In general, we need to add an extra bit to the maximum bit width only 44; if we can't prove that the upper bit of the original type is equal to 45; the upper bit of the proposed smaller type. If these two bits are the 46; same (either zero or one) we know that sign-extending from the smaller 47; type will result in the same value. Since we don't yet perform this 48; optimization, we make the proposed smaller type (i8) larger (i16) to 49; ensure correctness. 50; 51; CHECK: %[[S0:.+]] = sext <2 x i8> {{.*}} to <2 x i16> 52; CHECK: %[[OR:.+]] = or <2 x i16> %[[S0]], <i16 1, i16 1> 53; CHECK: %[[E0:.+]] = extractelement <2 x i16> %[[OR]], i32 0 54; CHECK: %[[S1:.+]] = sext i16 %[[E0]] to i64 55; CHECK: getelementptr inbounds i8, i8* %ptr, i64 %[[S1]] 56; CHECK: %[[E1:.+]] = extractelement <2 x i16> %[[OR]], i32 1 57; CHECK: %[[S2:.+]] = sext i16 %[[E1]] to i64 58; CHECK: getelementptr inbounds i8, i8* %ptr, i64 %[[S2]] 59; 60define i8 @PR31243_sext(i8 %v0, i8 %v1, i8 %v2, i8 %v3, i8* %ptr) { 61entry: 62 %tmp0 = sext i8 %v0 to i32 63 %tmp1 = sext i8 %v1 to i32 64 %tmp2 = or i32 %tmp0, 1 65 %tmp3 = or i32 %tmp1, 1 66 %tmp4 = getelementptr inbounds i8, i8* %ptr, i32 %tmp2 67 %tmp5 = getelementptr inbounds i8, i8* %ptr, i32 %tmp3 68 %tmp6 = load i8, i8* %tmp4 69 %tmp7 = load i8, i8* %tmp5 70 %tmp8 = add i8 %tmp6, %tmp7 71 ret i8 %tmp8 72} 73