[llvm] r188489 - Fixing a corner-case bug in strchr and strrchr lib call optimizations where

Gao, Yunzhong yunzhong_gao at playstation.sony.com
Wed Aug 21 15:14:48 PDT 2013


Sure. Fixed in r188941.

________________________________________
From: Bill Wendling [wendling at apple.com]
Sent: Wednesday, August 21, 2013 1:06 PM
To: Gao, Yunzhong
Cc: llvm-commits
Subject: Re: [llvm] r188489 - Fixing a corner-case bug in strchr and strrchr lib call optimizations where

On Aug 15, 2013, at 1:58 PM, Yunzhong Gao <Yunzhong_Gao at playstation.sony.com> wrote:

> Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=188489&r1=188488&r2=188489&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Thu Aug 15 15:58:59 2013
> @@ -477,7 +477,7 @@ struct StrChrOpt : public LibCallOptimiz
>
>     // Compute the offset, make sure to handle the case when we're searching for
>     // zero (a weird way to spell strlen).
> -    size_t I = CharC->getSExtValue() == 0 ?
> +    size_t I = (255 & CharC->getSExtValue()) == 0 ?

Hi Yunzhong,

Could you use 0xFF instead of 255 here (and below)? It makes it a bit clearer (at least to me) what's meant by the bitwise 'and' operator.

-bw

>         Str.size() : Str.find(CharC->getSExtValue());
>     if (I == StringRef::npos) // Didn't find the char.  strchr returns null.
>       return Constant::getNullValue(CI->getType());
> @@ -513,7 +513,7 @@ struct StrRChrOpt : public LibCallOptimi
>     }
>
>     // Compute the offset.
> -    size_t I = CharC->getSExtValue() == 0 ?
> +    size_t I = (255 & CharC->getSExtValue()) == 0 ?
>         Str.size() : Str.rfind(CharC->getSExtValue());
>     if (I == StringRef::npos) // Didn't find the char. Return null.
>       return Constant::getNullValue(CI->getType());
>
> Modified: llvm/trunk/test/Transforms/InstCombine/strchr-1.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/strchr-1.ll?rev=188489&r1=188488&r2=188489&view=diff
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/strchr-1.ll (original)
> +++ llvm/trunk/test/Transforms/InstCombine/strchr-1.ll Thu Aug 15 15:58:59 2013
> @@ -52,3 +52,14 @@ define void @test_simplify4(i32 %chr) {
>   store i8* %dst, i8** @chp
>   ret void
> }
> +
> +define void @test_simplify5() {
> +; CHECK: store i8* getelementptr inbounds ([14 x i8]* @hello, i32 0, i32 13)
> +; CHECK-NOT: call i8* @strchr
> +; CHECK: ret void
> +
> +  %src = getelementptr [14 x i8]* @hello, i32 0, i32 0
> +  %dst = call i8* @strchr(i8* %src, i32 65280)
> +  store i8* %dst, i8** @chp
> +  ret void
> +}
>
> Modified: llvm/trunk/test/Transforms/InstCombine/strrchr-1.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/strrchr-1.ll?rev=188489&r1=188488&r2=188489&view=diff
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/strrchr-1.ll (original)
> +++ llvm/trunk/test/Transforms/InstCombine/strrchr-1.ll Thu Aug 15 15:58:59 2013
> @@ -42,6 +42,17 @@ define void @test_simplify3() {
>   ret void
> }
>
> +define void @test_simplify4() {
> +; CHECK: store i8* getelementptr inbounds ([14 x i8]* @hello, i32 0, i32 13)
> +; CHECK-NOT: call i8* @strrchr
> +; CHECK: ret void
> +
> +  %src = getelementptr [14 x i8]* @hello, i32 0, i32 0
> +  %dst = call i8* @strrchr(i8* %src, i32 65280)
> +  store i8* %dst, i8** @chp
> +  ret void
> +}
> +
> define void @test_nosimplify1(i32 %chr) {
> ; CHECK-LABEL: @test_nosimplify1(
> ; CHECK: call i8* @strrchr
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits






More information about the llvm-commits mailing list