[llvm] r232903 - [SimplifyLibCalls] Fix negative shifts being produced by the memchr -> bitfield transform.
Benjamin Kramer
benny.kra at googlemail.com
Sat Mar 21 15:04:27 PDT 2015
Author: d0k
Date: Sat Mar 21 17:04:26 2015
New Revision: 232903
URL: http://llvm.org/viewvc/llvm-project?rev=232903&view=rev
Log:
[SimplifyLibCalls] Fix negative shifts being produced by the memchr -> bitfield transform.
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/trunk/test/Transforms/InstCombine/memchr.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=232903&r1=232902&r2=232903&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Sat Mar 21 17:04:26 2015
@@ -782,7 +782,9 @@ Value *LibCallSimplifier::optimizeMemChr
// memchr("\r\n", C, 2) != nullptr -> (C & ((1 << '\r') | (1 << '\n'))) != 0
// after bounds check.
if (!CharC && !Str.empty() && isOnlyUsedInZeroEqualityComparison(CI)) {
- unsigned char Max = *std::max_element(Str.begin(), Str.end());
+ unsigned char Max =
+ *std::max_element(reinterpret_cast<const unsigned char *>(Str.begin()),
+ reinterpret_cast<const unsigned char *>(Str.end()));
// Make sure the bit field we're about to create fits in a register on the
// target.
Modified: llvm/trunk/test/Transforms/InstCombine/memchr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/memchr.ll?rev=232903&r1=232902&r2=232903&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/memchr.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/memchr.ll Sat Mar 21 17:04:26 2015
@@ -9,6 +9,7 @@ target datalayout = "e-p:32:32:32-i1:8:8
@newlines = constant [3 x i8] c"\0D\0A\00"
@single = constant [2 x i8] c"\1F\00"
@spaces = constant [4 x i8] c" \0D\0A\00"
+ at negative = constant [3 x i8] c"\FF\FE\00"
@chp = global i8* zeroinitializer
declare i8* @memchr(i8*, i32, i32)
@@ -186,3 +187,14 @@ define i1 @test14(i32 %C) {
%cmp = icmp ne i8* %dst, null
ret i1 %cmp
}
+
+define i1 @test15(i32 %C) {
+; CHECK-LABEL: @test15
+; CHECK-NEXT: %dst = call i8* @memchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @negative, i32 0, i32 0), i32 %C, i32 3)
+; CHECK-NEXT: %cmp = icmp ne i8* %dst, null
+; CHECK-NEXT: ret i1 %cmp
+
+ %dst = call i8* @memchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @negative, i64 0, i64 0), i32 %C, i32 3)
+ %cmp = icmp ne i8* %dst, null
+ ret i1 %cmp
+}
More information about the llvm-commits
mailing list