A csmith test program that contained among other things adjacent stores of 16bit immediates:
t153: ch = store<ST2[getelementptr inbounds ([10 x [7 x i16]], [10 x [7 x i16]]* @g_112, i64 0, i64 9, i64 1)](tbaa=<0x2aa54f17a48>)> t151, Constant:i16<-7>, GlobalAddress:i64<[10 x [7 x i16]]* @g_112> + 128, undef:i64 t155: ch = store<ST2[getelementptr inbounds ([10 x [7 x i16]], [10 x [7 x i16]]* @g_112, i64 0, i64 9, i64 2)](tbaa=<0x2aa54f17a48>)> t153, Constant:i16<-7>, GlobalAddress:i64<[10 x [7 x i16]]* @g_112> + 130, undef:i64 t157: ch = store<ST2[getelementptr inbounds ([10 x [7 x i16]], [10 x [7 x i16]]* @g_112, i64 0, i64 9, i64 3)](tbaa=<0x2aa54f17a48>)> t155, Constant:i16<-7>, GlobalAddress:i64<[10 x [7 x i16]]* @g_112> + 132, undef:i64 t159: ch = store<ST2[getelementptr inbounds ([10 x [7 x i16]], [10 x [7 x i16]]* @g_112, i64 0, i64 9, i64 4)](tbaa=<0x2aa54f17a48>)> t157, Constant:i16<-7>, GlobalAddress:i64<[10 x [7 x i16]]* @g_112> + 134, undef:i64 t161: ch = store<ST2[getelementptr inbounds ([10 x [7 x i16]], [10 x [7 x i16]]* @g_112, i64 0, i64 9, i64 5)](tbaa=<0x2aa54f17a48>)> t159, Constant:i16<-7>, GlobalAddress:i64<[10 x [7 x i16]]* @g_112> + 136, undef:i64 t163: ch = store<ST2[getelementptr inbounds ([10 x [7 x i16]], [10 x [7 x i16]]* @g_112, i64 0, i64 9, i64 6)](tbaa=<0x2aa54f17a48>)> t161, Constant:i16<-7>, GlobalAddress:i64<[10 x [7 x i16]]* @g_112> + 138, undef:i64
-> Type-legalized selection DAG:
(i16 is not a legal type in the SystemZ backend, so the stores are converted to truncating stores of -7 of type i32.)
t362: ch = store<ST2[getelementptr inbounds ([10 x [7 x i16]], [10 x [7 x i16]]* @g_112, i64 0, i64 8, i64 5)](tbaa=<0x2aa54f17a48>), trunc to i16> t361, Constant:i32<-7>, GlobalAddress:i64<[10 x [7 x i16]]* @g_112> + 122, undef:i64 t363: ch = store<ST2[getelementptr inbounds ([10 x [7 x i16]], [10 x [7 x i16]]* @g_112, i64 0, i64 8, i64 6)](tbaa=<0x2aa54f17a48>), trunc to i16> t362, Constant:i32<-7>, GlobalAddress:i64<[10 x [7 x i16]]* @g_112> + 124, undef:i64 t364: ch = store<ST2[getelementptr inbounds ([10 x [7 x i16]], [10 x [7 x i16]]* @g_112, i64 0, i64 9, i64 0)](tbaa=<0x2aa54f17a48>), trunc to i16> t363, Constant:i32<-7>, GlobalAddress:i64<[10 x [7 x i16]]* @g_112> + 126, undef:i64 t365: ch = store<ST2[getelementptr inbounds ([10 x [7 x i16]], [10 x [7 x i16]]* @g_112, i64 0, i64 9, i64 1)](tbaa=<0x2aa54f17a48>), trunc to i16> t364, Constant:i32<-7>, GlobalAddress:i64<[10 x [7 x i16]]* @g_112> + 128, undef:i64 t366: ch = store<ST2[getelementptr inbounds ([10 x [7 x i16]], [10 x [7 x i16]]* @g_112, i64 0, i64 9, i64 2)](tbaa=<0x2aa54f17a48>), trunc to i16> t365, Constant:i32<-7>, GlobalAddress:i64<[10 x [7 x i16]]* @g_112> + 130, undef:i64 t367: ch = store<ST2[getelementptr inbounds ([10 x [7 x i16]], [10 x [7 x i16]]* @g_112, i64 0, i64 9, i64 3)](tbaa=<0x2aa54f17a48>), trunc to i16> t366, Constant:i32<-7>, GlobalAddress:i64<[10 x [7 x i16]]* @g_112> + 132, undef:i64
-> Optimized type-legalized selection DAG: BB
DAGCombiner merges stores but they will store -7, wich is wrong:
t398: ch = store<ST4[getelementptr inbounds ([10 x [7 x i16]], [10 x [7 x i16]]* @g_112, i64 0, i64 9, i64 4)](align=2)> t348, Constant:i32<-7>, GlobalAddress:i64<[10 x [7 x i16]]* @g_112> + 134, undef:i64 t399: ch = store<ST8[getelementptr inbounds ([10 x [7 x i16]], [10 x [7 x i16]]* @g_112, i64 0, i64 9, i64 0)](align=2)> t348, Constant:i64<-7>, GlobalAddress:i64<[10 x [7 x i16]]* @g_112> + 126, undef:i64
This patch seems to fix the problem by fixing the way the new constant is built for a truncating store.