Files
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
clang-tools-extra
compiler-rt
eng
libcxx
libcxxabi
libunwind
lld
lldb
llvm
bindings
cmake
docs
examples
include
lib
projects
resources
runtimes
scripts
test
Analysis
Assembler
Bindings
Bitcode
BugPoint
CodeGen
DebugInfo
Examples
ExecutionEngine
Feature
FileCheck
Instrumentation
Integer
JitListener
LTO
Linker
MC
Object
ObjectYAML
Other
SafepointIRVerifier
SymbolRewriter
TableGen
ThinLTO
Transforms
ADCE
AddDiscriminators
AlignmentFromAssumptions
ArgumentPromotion
AtomicExpand
BDCE
BranchFolding
CallSiteSplitting
CalledValuePropagation
CodeExtractor
CodeGenPrepare
ConstProp
ConstantHoisting
ConstantMerge
Coroutines
CorrelatedValuePropagation
CrossDSOCFI
DCE
DeadArgElim
DeadStoreElimination
DivRemPairs
EarlyCSE
EliminateAvailableExternally
EntryExitInstrumenter
ExpandMemCmp
Float2Int
ForcedFunctionAttrs
FunctionAttrs
FunctionImport
GCOVProfiling
GVN
GVNHoist
GVNSink
GlobalDCE
GlobalMerge
GlobalOpt
GlobalSplit
GuardWidening
IPConstantProp
IRCE
IndVarSimplify
IndirectBrExpand
InferAddressSpaces
InferFunctionAttrs
Inline
InstCombine
InstMerge
InstNamer
InstSimplify
2010-12-20-Boolean.ll
2011-01-14-Thread.ll
2011-02-01-Vector.ll
2011-09-05-InsertExtractValue.ll
2011-10-27-BinOpCrash.ll
2011-11-23-MaskedBitsCrash.ll
2013-04-19-ConstantFoldingCrash.ll
AndOrXor.ll
add-mask.ll
addsub.ll
and-icmps-same-ops.ll
assume.ll
bitcast-vector-fold.ll
bitreverse-fold.ll
bitreverse.ll
bswap.ll
call-callconv.ll
call.ll
cast.ll
compare.ll
dead-code-removal.ll
div.ll
exact-nsw-nuw.ll
exp-intrinsic.ll
exp2-intrinsic.ll
extract-element.ll
fast-math.ll
fdiv.ll
floating-point-arithmetic.ll
floating-point-compare.ll
fold-builtin-fma.ll
fold-intrinsics.ll
gep.ll
icmp-bool-constant.ll
icmp-constant.ll
icmp-ranges.ll.REMOVED.git-id
implies.ll
insertelement.ll
load-relative-32.ll
load-relative.ll
load.ll
log-intrinsic.ll
log2-intrinsic.ll
logic-of-fcmps.ll
maxmin.ll
mul.ll
negate.ll
noalias-ptr.ll
or-icmps-same-ops.ll
or.ll
past-the-end.ll
phi.ll
pr28725.ll
pr33957.ll
ptr_diff.ll
reassociate.ll
rem.ll
require-dominator.ll
returned.ll
select.ll
shift-128-kb.ll
shift-knownbits.ll
shr-nop.ll
shufflevector.ll
signed-div-rem.ll
simplify-nested-bitcast.ll
undef.ll
vec-cmp.ll
vector_gep.ll
vector_ptr_bitcast.ll
InterleavedAccess
Internalize
JumpThreading
LCSSA
LICM
LoadStoreVectorizer
LoopDataPrefetch
LoopDeletion
LoopDistribute
LoopIdiom
LoopInterchange
LoopLoadElim
LoopPredication
LoopReroll
LoopRotate
LoopSimplify
LoopSimplifyCFG
LoopStrengthReduce
LoopUnroll
LoopUnswitch
LoopVectorize
LoopVersioning
LoopVersioningLICM
LowerAtomic
LowerExpectIntrinsic
LowerGuardIntrinsic
LowerInvoke
LowerSwitch
LowerTypeTests
Mem2Reg
MemCpyOpt
MergeFunc
MergeICmps
MetaRenamer
NameAnonGlobals
NaryReassociate
NewGVN
ObjCARC
PGOProfile
PartiallyInlineLibCalls
PhaseOrdering
PlaceSafepoints
PreISelIntrinsicLowering
PruneEH
Reassociate
Reg2Mem
RewriteStatepointsForGC
SCCP
SLPVectorizer
SROA
SafeStack
SampleProfile
Scalarizer
SeparateConstOffsetFromGEP
SimpleLoopUnswitch
SimplifyCFG
Sink
SpeculateAroundPHIs
SpeculativeExecution
StraightLineStrengthReduce
StripDeadPrototypes
StripSymbols
StructurizeCFG
TailCallElim
ThinLTOBitcodeWriter
Util
WholeProgramDevirt
Unit
Verifier
YAMLParser
tools
.clang-format
CMakeLists.txt
TestRunner.sh
lit.cfg.py
lit.site.cfg.py.in
tools
unittests
utils
.arcconfig
.clang-format
.clang-tidy
.gitattributes
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
CREDITS.TXT
LICENSE.TXT
LLVMBuild.txt
README.txt
RELEASE_TESTERS.TXT
configure
llvm.spec.in
version.txt.in
nuget
openmp
polly
Directory.Build.props
Directory.Build.targets
NuGet.config
azure-pipelines.yml
build.cmd
build.sh
dir.common.props
global.json
llvm.proj
mxe-Win64.cmake.in
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h

224 lines
4.2 KiB
LLVM
Raw Normal View History

; NOTE: Assertions have been autogenerated by update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s
define i32 @add1(i32 %x) {
; CHECK-LABEL: @add1(
; CHECK: ret i32 %x
;
; (X + -1) + 1 -> X
%l = add i32 %x, -1
%r = add i32 %l, 1
ret i32 %r
}
define i32 @and1(i32 %x, i32 %y) {
; CHECK-LABEL: @and1(
; CHECK: [[L:%.*]] = and i32 %x, %y
; CHECK-NEXT: ret i32 [[L]]
;
; (X & Y) & X -> X & Y
%l = and i32 %x, %y
%r = and i32 %l, %x
ret i32 %r
}
define i32 @and2(i32 %x, i32 %y) {
; CHECK-LABEL: @and2(
; CHECK: [[R:%.*]] = and i32 %x, %y
; CHECK-NEXT: ret i32 [[R]]
;
; X & (X & Y) -> X & Y
%r = and i32 %x, %y
%l = and i32 %x, %r
ret i32 %l
}
define i32 @or1(i32 %x, i32 %y) {
; CHECK-LABEL: @or1(
; CHECK: [[L:%.*]] = or i32 %x, %y
; CHECK-NEXT: ret i32 [[L]]
;
; (X | Y) | X -> X | Y
%l = or i32 %x, %y
%r = or i32 %l, %x
ret i32 %r
}
define i32 @or2(i32 %x, i32 %y) {
; CHECK-LABEL: @or2(
; CHECK: [[R:%.*]] = or i32 %x, %y
; CHECK-NEXT: ret i32 [[R]]
;
; X | (X | Y) -> X | Y
%r = or i32 %x, %y
%l = or i32 %x, %r
ret i32 %l
}
define i32 @xor1(i32 %x, i32 %y) {
; CHECK-LABEL: @xor1(
; CHECK: ret i32 %y
;
; (X ^ Y) ^ X = Y
%l = xor i32 %x, %y
%r = xor i32 %l, %x
ret i32 %r
}
define i32 @xor2(i32 %x, i32 %y) {
; CHECK-LABEL: @xor2(
; CHECK: ret i32 %y
;
; X ^ (X ^ Y) = Y
%r = xor i32 %x, %y
%l = xor i32 %x, %r
ret i32 %l
}
define i32 @sub1(i32 %x, i32 %y) {
; CHECK-LABEL: @sub1(
; CHECK: ret i32 %y
;
%d = sub i32 %x, %y
%r = sub i32 %x, %d
ret i32 %r
}
define i32 @sub2(i32 %x) {
; CHECK-LABEL: @sub2(
; CHECK: ret i32 -1
;
; X - (X + 1) -> -1
%xp1 = add i32 %x, 1
%r = sub i32 %x, %xp1
ret i32 %r
}
define i32 @sub3(i32 %x, i32 %y) {
; CHECK-LABEL: @sub3(
; CHECK: ret i32 %x
;
; ((X + 1) + Y) - (Y + 1) -> X
%xp1 = add i32 %x, 1
%lhs = add i32 %xp1, %y
%rhs = add i32 %y, 1
%r = sub i32 %lhs, %rhs
ret i32 %r
}
define i32 @sdiv1(i32 %x, i32 %y) {
; CHECK-LABEL: @sdiv1(
; CHECK: ret i32 %x
;
; (no overflow X * Y) / Y -> X
%mul = mul nsw i32 %x, %y
%r = sdiv i32 %mul, %y
ret i32 %r
}
define i32 @sdiv2(i32 %x, i32 %y) {
; CHECK-LABEL: @sdiv2(
; CHECK: [[DIV:%.*]] = sdiv i32 %x, %y
; CHECK-NEXT: ret i32 [[DIV]]
;
; (((X / Y) * Y) / Y) -> X / Y
%div = sdiv i32 %x, %y
%mul = mul i32 %div, %y
%r = sdiv i32 %mul, %y
ret i32 %r
}
define i32 @sdiv3(i32 %x, i32 %y) {
; CHECK-LABEL: @sdiv3(
; CHECK: ret i32 0
;
; (X rem Y) / Y -> 0
%rem = srem i32 %x, %y
%div = sdiv i32 %rem, %y
ret i32 %div
}
define i32 @sdiv4(i32 %x, i32 %y) {
; CHECK-LABEL: @sdiv4(
; CHECK: ret i32 %x
;
; (X / Y) * Y -> X if the division is exact
%div = sdiv exact i32 %x, %y
%mul = mul i32 %div, %y
ret i32 %mul
}
define i32 @sdiv5(i32 %x, i32 %y) {
; CHECK-LABEL: @sdiv5(
; CHECK: ret i32 %x
;
; Y * (X / Y) -> X if the division is exact
%div = sdiv exact i32 %x, %y
%mul = mul i32 %y, %div
ret i32 %mul
}
define i32 @udiv1(i32 %x, i32 %y) {
; CHECK-LABEL: @udiv1(
; CHECK: ret i32 %x
;
; (no overflow X * Y) / Y -> X
%mul = mul nuw i32 %x, %y
%r = udiv i32 %mul, %y
ret i32 %r
}
define i32 @udiv2(i32 %x, i32 %y) {
; CHECK-LABEL: @udiv2(
; CHECK: [[DIV:%.*]] = udiv i32 %x, %y
; CHECK-NEXT: ret i32 [[DIV]]
;
; (((X / Y) * Y) / Y) -> X / Y
%div = udiv i32 %x, %y
%mul = mul i32 %div, %y
%r = udiv i32 %mul, %y
ret i32 %r
}
define i32 @udiv3(i32 %x, i32 %y) {
; CHECK-LABEL: @udiv3(
; CHECK: ret i32 0
;
; (X rem Y) / Y -> 0
%rem = urem i32 %x, %y
%div = udiv i32 %rem, %y
ret i32 %div
}
define i32 @udiv4(i32 %x, i32 %y) {
; CHECK-LABEL: @udiv4(
; CHECK: ret i32 %x
;
; (X / Y) * Y -> X if the division is exact
%div = udiv exact i32 %x, %y
%mul = mul i32 %div, %y
ret i32 %mul
}
define i32 @udiv5(i32 %x, i32 %y) {
; CHECK-LABEL: @udiv5(
; CHECK: ret i32 %x
;
; Y * (X / Y) -> X if the division is exact
%div = udiv exact i32 %x, %y
%mul = mul i32 %y, %div
ret i32 %mul
}
define i16 @trunc1(i32 %x) {
; CHECK-LABEL: @trunc1(
; CHECK: ret i16 1
;
%y = add i32 %x, 1
%tx = trunc i32 %x to i16
%ty = trunc i32 %y to i16
%d = sub i16 %ty, %tx
ret i16 %d
}