[PATCH] D72396: [InstCombine] fold zext of masked bit set/clear
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 8 09:24:36 PST 2020
lebedev.ri requested changes to this revision.
lebedev.ri added a comment.
This revision now requires changes to proceed.
I agree that this seem to be either causing, or triggering, a miscompile.
Most standalone testcase: https://godbolt.org/z/EMWGof
On rG19ace449a3da4058428495283b3b15826f8d7d34 <https://reviews.llvm.org/rG19ace449a3da4058428495283b3b15826f8d7d34>, this compiles to:
; ModuleID = '/tmp/test.cpp'
source_filename = "/tmp/test.cpp"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: norecurse nounwind readnone uwtable
define dso_local i32 @_Z1fjjj(i32 %olds, i32 %news, i32 %mask) local_unnamed_addr #0 {
entry:
%0 = and i32 %mask, 1
ret i32 %0
}
attributes #0 = { norecurse nounwind readnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.module.flags = !{!0}
!llvm.ident = !{!1}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 10.0.0 (git at github.com:LebedevRI/llvm-project.git debb93d97f264d542b0d9ca6f2f50f0fd72c7356)"}
but with this patch reversed, it compiles to
; ModuleID = '/tmp/test.cpp'
source_filename = "/tmp/test.cpp"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: norecurse nounwind readnone uwtable
define dso_local i32 @_Z1fjjj(i32 %olds, i32 %news, i32 %mask) local_unnamed_addr #0 {
entry:
%cmp1 = icmp ne i32 %news, %olds
%and = and i32 %mask, 1
%cmp110 = zext i1 %cmp1 to i32
%conv12 = or i32 %and, %cmp110
ret i32 %conv12
}
attributes #0 = { norecurse nounwind readnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.module.flags = !{!0}
!llvm.ident = !{!1}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 10.0.0 (git at github.com:LebedevRI/llvm-project.git debb93d97f264d542b0d9ca6f2f50f0fd72c7356)"}
----------------------------------------
define i32 @_Z1fjjj(i32 %olds, i32 %news, i32 %mask) {
%entry:
%cmp1 = icmp ne i32 %news, %olds
%and = and i32 %mask, 1
%cmp110 = zext i1 %cmp1 to i32
%conv12 = or i32 %and, %cmp110
ret i32 %conv12
}
=>
define i32 @_Z1fjjj(i32 %olds, i32 %news, i32 %mask) {
%entry:
%0 = and i32 %mask, 1
ret i32 %0
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
i32 %olds = #x00080000 (524288)
i32 %news = #x00000000 (0)
i32 %mask = undef
Source:
i1 %cmp1 = #x1 (1)
i32 %and = #x00000000 (0) [based on undef value]
i32 %cmp110 = #x00000001 (1)
i32 %conv12 = #x00000001 (1)
Target:
i32 %0 = #x00000000 (0)
Source value: #x00000001 (1)
Target value: #x00000000 (0)
Summary:
0 correct transformations
1 incorrect transformations
0 errors
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D72396/new/
https://reviews.llvm.org/D72396
More information about the llvm-commits
mailing list