llvm.org GIT mirror llvm / a54b82a
ValueTracking: Make isBytewiseValue simpler and more powerful at the same time. Turns out there is a simpler way of checking that all bytes in a word are equal than binary decomposition. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228503 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 4 years ago
2 changed file(s) with 24 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
21202120 // Don't handle long double formats, which have strange constraints.
21212121 }
21222122
2123 // We can handle constant integers that are power of two in size and a
2124 // multiple of 8 bits.
2123 // We can handle constant integers that are multiple of 8 bits.
21252124 if (ConstantInt *CI = dyn_cast(V)) {
2126 unsigned Width = CI->getBitWidth();
2127 if (isPowerOf2_32(Width) && Width > 8) {
2128 // We can handle this value if the recursive binary decomposition is the
2129 // same at all levels.
2130 APInt Val = CI->getValue();
2131 APInt Val2;
2132 while (Val.getBitWidth() != 8) {
2133 unsigned NextWidth = Val.getBitWidth()/2;
2134 Val2 = Val.lshr(NextWidth);
2135 Val2 = Val2.trunc(Val.getBitWidth()/2);
2136 Val = Val.trunc(Val.getBitWidth()/2);
2137
2138 // If the top/bottom halves aren't the same, reject it.
2139 if (Val != Val2)
2140 return nullptr;
2141 }
2142 return ConstantInt::get(V->getContext(), Val);
2125 if (CI->getBitWidth() % 8 == 0) {
2126 assert(CI->getBitWidth() > 8 && "8 bits should be handled above!");
2127
2128 // We can check that all bytes of an integer are equal by making use of a
2129 // little trick: rotate by 8 and check if it's still the same value.
2130 if (CI->getValue() != CI->getValue().rotl(8))
2131 return nullptr;
2132 return ConstantInt::get(V->getContext(), CI->getValue().trunc(8));
21432133 }
21442134 }
21452135
283283 ; CHECK-NOT: memset
284284 ; CHECK: ret void
285285 }
286
287 ; Memset followed by odd store.
288 define void @test11(i32* nocapture %P) nounwind ssp {
289 entry:
290 %add.ptr = getelementptr inbounds i32* %P, i64 3
291 %0 = bitcast i32* %add.ptr to i8*
292 tail call void @llvm.memset.p0i8.i64(i8* %0, i8 1, i64 11, i32 1, i1 false)
293 %arrayidx = getelementptr inbounds i32* %P, i64 0
294 %arrayidx.cast = bitcast i32* %arrayidx to i96*
295 store i96 310698676526526814092329217, i96* %arrayidx.cast, align 4
296 ret void
297 ; CHECK-LABEL: @test11(
298 ; CHECK-NOT: store
299 ; CHECK: call void @llvm.memset.p0i8.i64(i8* %1, i8 1, i64 23, i32 4, i1 false)
300 }