Skip to content

Instantly share code, notes, and snippets.

@doersino
Forked from tvh/dotp.s
Last active July 6, 2016 18:43
Show Gist options
  • Save doersino/05f70a6e03c7b685544bc34b741330b5 to your computer and use it in GitHub Desktop.
Save doersino/05f70a6e03c7b685544bc34b741330b5 to your computer and use it in GitHub Desktop.
This fork works with llvm-general-3.4.6.0.
; ModuleID = 'dotp.c'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: nounwind readonly uwtable
define float @dotp(float* nocapture %a, float* nocapture %b, i32 %count) #0 {
%1 = icmp sgt i32 %count, 0
br i1 %1, label %.lr.ph, label %._crit_edge
.lr.ph: ; preds = %0, %.lr.ph
%indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
%res.01 = phi float [ %7, %.lr.ph ], [ 0.000000e+00, %0 ]
%2 = getelementptr inbounds float* %a, i64 %indvars.iv
%3 = load float* %2, align 4, !tbaa !0
%4 = getelementptr inbounds float* %b, i64 %indvars.iv
%5 = load float* %4, align 4, !tbaa !0
%6 = fmul fast float %3, %5
%7 = fadd fast float %res.01, %6
%indvars.iv.next = add i64 %indvars.iv, 1
%lftr.wideiv = trunc i64 %indvars.iv.next to i32
%exitcond = icmp eq i32 %lftr.wideiv, %count
br i1 %exitcond, label %._crit_edge, label %.lr.ph
._crit_edge: ; preds = %.lr.ph, %0
%res.0.lcssa = phi float [ 0.000000e+00, %0 ], [ %7, %.lr.ph ]
ret float %res.0.lcssa
}
attributes #0 = { nounwind readonly uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-frame-pointer-elim-non-leaf"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }
!0 = metadata !{metadata !"float", metadata !1}
!1 = metadata !{metadata !"omnipotent char", metadata !2}
!2 = metadata !{metadata !"Simple C/C++ TBAA"}
import LLVM.General.Context
import LLVM.General.Module
import Control.Monad.Except
import LLVM.General.PassManager
import LLVM.General.Transforms
main :: IO ()
main = do
mt <- readFile "dotp.s"
_ <- withContext $ \cx -> runExceptT $ withModuleFromLLVMAssembly cx mt $ \modu -> do
let ps = defaultCuratedPassSetSpec {optLevel=Just 3}
ps1 = defaultPassSetSpec {transforms=[LoopVectorize True]}
b1 <- withPassManager ps $ \pm -> runPassManager pm modu
b2 <- withPassManager ps1 $ \pm -> runPassManager pm modu
print [b1,b2]
moduleLLVMAssembly modu >>= putStrLn
print defaultVectorizeBasicBlocks
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment