Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
Go
Haskell
HLSL
Hook
Hylo
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
Zig
Javascript
GIMPLE
llvm source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
clang (assertions trunk)
clang (trunk)
clang 10.0.0
clang 10.0.1
clang 11.0.0
clang 11.0.1
clang 12.0.0
clang 12.0.1
clang 13.0.0
clang 14.0.0
clang 15.0.0
clang 16.0.0
clang 17.0.1
clang 18.1.0
clang 4.0.1
clang 5.0.0
clang 6.0.0
clang 7.0.0
clang 8.0.0
clang 9.0.0
llc (assertions trunk)
llc (trunk)
llc 10.0.0
llc 10.0.1
llc 11.0.0
llc 11.0.1
llc 12.0.0
llc 12.0.1
llc 13.0.0
llc 14.0.0
llc 15.0.0
llc 16.0.0
llc 17.0.1
llc 18.1.0
llc 3.2
llc 3.3
llc 3.9.1
llc 4.0.0
llc 4.0.1
llc 5.0.0
llc 6.0.0
llc 7.0.0
llc 8.0.0
llc 9.0.0
opt (assertions trunk)
opt (trunk)
opt 10.0.0
opt 10.0.1
opt 11.0.0
opt 11.0.1
opt 12.0.0
opt 12.0.1
opt 13.0.0
opt 14.0.0
opt 15.0.0
opt 16.0.0
opt 17.0.1
opt 18.1.0
opt 3.2
opt 3.3
opt 3.9.1
opt 4.0.0
opt 4.0.1
opt 5.0.0
opt 6.0.0
opt 7.0.0
opt 8.0.0
opt 9.0.0
Options
Source code
; RUN: opt -correlated-propagation -S %s | FileCheck %s target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.10.0" ; Make sure CVP (via LVI) can propagate values through sadd.with.overflow. ; CHECK-LABEL: @sadd1 define i1 @sadd1(i32 %x, i32 %y) #0 { entry: %x.offset = add i32 %x, 9 %cmp1 = icmp ult i32 %x.offset, 19 br i1 %cmp1, label %cont1, label %out cont1: %y.offset = add i32 %y, 9 %cmp2 = icmp ult i32 %y.offset, 19 br i1 %cmp2, label %cont2, label %out cont2: ; x = [-9,10), y = [-9,10) %res = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %x, i32 %y) %add = extractvalue { i32, i1 } %res, 0 br label %cont3 cont3: ; add = [-18,19) %cmp3 = icmp slt i32 %add, 19 br label %out out: %ret = phi i1 [ true, %entry], [ true, %cont1 ], [ %cmp3, %cont3 ] ; CHECK: ret i1 true ret i1 %ret } ; Negative version of previous test. ; CHECK-LABEL: @sadd2 define i1 @sadd2(i32 %x, i32 %y) #0 { entry: %x.offset = add i32 %x, 9 %cmp1 = icmp ult i32 %x.offset, 19 br i1 %cmp1, label %cont1, label %out cont1: %y.offset = add i32 %y, 9 %cmp2 = icmp ult i32 %y.offset, 19 br i1 %cmp2, label %cont2, label %out cont2: ; x = [-9,10), y = [-9,10) %res = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %x, i32 %y) %add = extractvalue { i32, i1 } %res, 0 br label %cont3 cont3: ; add = [-18,19) %cmp3 = icmp slt i32 %add, 18 br label %out out: %ret = phi i1 [ true, %entry], [ true, %cont1 ], [ %cmp3, %cont3 ] ; CHECK-NOT: ret i1 true ret i1 %ret } ; Make sure CVP (via LVI) can propagate values through uadd.with.overflow. ; CHECK-LABEL: @uadd1 define i1 @uadd1(i32 %x, i32 %y) #0 { entry: %cmp1 = icmp ult i32 %x, 10 br i1 %cmp1, label %cont1, label %out cont1: %cmp2 = icmp ult i32 %y, 10 br i1 %cmp2, label %cont2, label %out cont2: %res = tail call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %x, i32 %y) %add = extractvalue { i32, i1 } %res, 0 br label %cont3 cont3: %cmp3 = icmp ult i32 %add, 19 br label %out out: %ret = phi i1 [ true, %entry], [ true, %cont1 ], [ %cmp3, %cont3 ] ; CHECK: ret i1 true ret i1 %ret } ; Negative version of previous test. ; CHECK-LABEL: @uadd2 define i1 @uadd2(i32 %x, i32 %y) #0 { entry: %cmp1 = icmp ult i32 %x, 10 br i1 %cmp1, label %cont1, label %out cont1: %cmp2 = icmp ult i32 %y, 10 br i1 %cmp2, label %cont2, label %out cont2: ; x = [0,10), y = [0,10) %res = tail call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %x, i32 %y) %add = extractvalue { i32, i1 } %res, 0 br label %cont3 cont3: %cmp3 = icmp ult i32 %add, 18 br label %out out: %ret = phi i1 [ true, %entry], [ true, %cont1 ], [ %cmp3, %cont3 ] ; CHECK-NOT: ret i1 true ret i1 %ret } ; Make sure CVP (via LVI) can propagate values through ssub.with.overflow. ; CHECK-LABEL: @ssub1 define i1 @ssub1(i32 %x, i32 %y) #0 { entry: %cmp1 = icmp ult i32 %x, 10 br i1 %cmp1, label %cont1, label %out cont1: %cmp2 = icmp ult i32 %y, 10 br i1 %cmp2, label %cont2, label %out cont2: %offset = add i32 %x, 9 ; x = [0,10), y = [0,10), offset = [9,19) %res = tail call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 %offset, i32 %y) %sub = extractvalue { i32, i1 } %res, 0 br label %cont3 cont3: %cmp3 = icmp ult i32 %sub, 19 br label %out out: %ret = phi i1 [ true, %entry], [ true, %cont1 ], [ %cmp3, %cont3 ] ; CHECK: ret i1 true ret i1 %ret } ; Negative version of previous test. ; CHECK-LABEL: @ssub2 define i1 @ssub2(i32 %x, i32 %y) #0 { entry: %cmp1 = icmp ult i32 %x, 10 br i1 %cmp1, label %cont1, label %out cont1: %cmp2 = icmp ult i32 %y, 10 br i1 %cmp2, label %cont2, label %out cont2: %offset = add i32 %x, 8 ; x = [0,10), y = [0,10), offset = [8,18) %res = tail call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 %offset, i32 %y) %sub = extractvalue { i32, i1 } %res, 0 br label %cont3 cont3: %cmp3 = icmp ult i32 %sub, 19 br label %out out: %ret = phi i1 [ true, %entry], [ true, %cont1 ], [ %cmp3, %cont3 ] ; CHECK-NOT: ret i1 true ret i1 %ret } ; Make sure CVP (via LVI) can propagate values through usub.with.overflow. ; CHECK-LABEL: @usub1 define i1 @usub1(i32 %x, i32 %y) #0 { entry: %cmp1 = icmp ult i32 %x, 10 br i1 %cmp1, label %cont1, label %out cont1: %cmp2 = icmp ult i32 %y, 10 br i1 %cmp2, label %cont2, label %out cont2: %offset = add i32 %x, 9 ; x = [0,10), y = [0,10), offset = [9,19) %res = tail call { i32, i1 } @llvm.usub.with.overflow.i32(i32 %offset, i32 %y) %sub = extractvalue { i32, i1 } %res, 0 br label %cont3 cont3: %cmp3 = icmp ult i32 %sub, 19 br label %out out: %ret = phi i1 [ true, %entry], [ true, %cont1 ], [ %cmp3, %cont3 ] ; CHECK: ret i1 true ret i1 %ret } ; Negative version of previous test. ; CHECK-LABEL: @usub2 define i1 @usub2(i32 %x, i32 %y) #0 { entry: %cmp1 = icmp ult i32 %x, 10 br i1 %cmp1, label %cont1, label %out cont1: %cmp2 = icmp ult i32 %y, 10 br i1 %cmp2, label %cont2, label %out cont2: %offset = add i32 %x, 9 ; x = [0,10), y = [0,10), offset = [9,19) %res = tail call { i32, i1 } @llvm.usub.with.overflow.i32(i32 %offset, i32 %y) %sub = extractvalue { i32, i1 } %res, 0 br label %cont3 cont3: %cmp3 = icmp ult i32 %sub, 18 br label %out out: %ret = phi i1 [ true, %entry], [ true, %cont1 ], [ %cmp3, %cont3 ] ; CHECK-NOT: ret i1 true ret i1 %ret } ; Make sure CVP (via LVI) can propagate values through smul.with.overflow. ; CHECK-LABEL: @smul1 define i1 @smul1(i32 %x, i32 %y) #0 { entry: %x.offset = add i32 %x, 9 %cmp1 = icmp ult i32 %x.offset, 19 br i1 %cmp1, label %cont1, label %out cont1: %y.offset = add i32 %y, 9 %cmp2 = icmp ult i32 %y.offset, 19 br i1 %cmp2, label %cont2, label %out cont2: ; x = [-9,10), y = [-9,10) %res = tail call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %x, i32 %y) %mul = extractvalue { i32, i1 } %res, 0 br label %cont3 cont3: %cmp3 = icmp sle i32 %mul, 81 %cmp4 = icmp sge i32 %mul, -81 %cmp5 = and i1 %cmp3, %cmp4 br label %out out: %ret = phi i1 [ true, %entry], [ true, %cont1 ], [ %cmp5, %cont3 ] ; CHECK: ret i1 true ret i1 %ret } ; Negative version of previous test. ; CHECK-LABEL: @smul2 define i1 @smul2(i32 %x, i32 %y) #0 { entry: %x.offset = add i32 %x, 9 %cmp1 = icmp ult i32 %x.offset, 19 br i1 %cmp1, label %cont1, label %out cont1: %y.offset = add i32 %y, 9 %cmp2 = icmp ult i32 %y.offset, 19 br i1 %cmp2, label %cont2, label %out cont2: ; x = [-9,10), y = [-9,10) %res = tail call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %x, i32 %y) %mul = extractvalue { i32, i1 } %res, 0 br label %cont3 cont3: %cmp3 = icmp slt i32 %mul, 81 br label %out out: %ret = phi i1 [ true, %entry], [ true, %cont1 ], [ %cmp3, %cont3 ] ; CHECK-NOT: ret i1 true ret i1 %ret } ; Make sure CVP (via LVI) can propagate values through umul.with.overflow. ; CHECK-LABEL: @umul1 define i1 @umul1(i32 %x, i32 %y) #0 { entry: %cmp1 = icmp ult i32 %x, 100 br i1 %cmp1, label %cont1, label %out cont1: %cmp2 = icmp ult i32 %y, 100 br i1 %cmp2, label %cont2, label %out cont2: %res = tail call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %x, i32 %y) %mul = extractvalue { i32, i1 } %res, 0 br label %cont3 cont3: %cmp3 = icmp ule i32 %mul, 9801 br label %out out: %ret = phi i1 [ true, %entry], [ true, %cont1 ], [ %cmp3, %cont3 ] ; CHECK: ret i1 true ret i1 %ret } ; Negative version of previous test. ; CHECK-LABEL: @umul2 define i1 @umul2(i32 %x, i32 %y) #0 { entry: %cmp1 = icmp ult i32 %x, 100 br i1 %cmp1, label %cont1, label %out cont1: %cmp2 = icmp ult i32 %y, 100 br i1 %cmp2, label %cont2, label %out cont2: %res = tail call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %x, i32 %y) %mul = extractvalue { i32, i1 } %res, 0 br label %cont3 cont3: %cmp3 = icmp ult i32 %mul, 9801 br label %out out: %ret = phi i1 [ true, %entry], [ true, %cont1 ], [ %cmp3, %cont3 ] ; CHECK-NOT: ret i1 true ret i1 %ret } declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32) #1 declare { i32, i1 } @llvm.uadd.with.overflow.i32(i32, i32) #1 declare { i32, i1 } @llvm.ssub.with.overflow.i32(i32, i32) #1 declare { i32, i1 } @llvm.usub.with.overflow.i32(i32, i32) #1 declare { i32, i1 } @llvm.smul.with.overflow.i32(i32, i32) #1 declare { i32, i1 } @llvm.umul.with.overflow.i32(i32, i32) #1
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree