Skip to content

Instantly share code, notes, and snippets.

@sueszli
Created April 19, 2026 19:53
Show Gist options
  • Select an option

  • Save sueszli/4332e0c9304ca089b4d64fb026195284 to your computer and use it in GitHub Desktop.

Select an option

Save sueszli/4332e0c9304ca089b4d64fb026195284 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Repro for PR #5878 review: three tools disagree on fastmath on int-returning calls
set -u
MLIR=/tmp/hello-sasha.mlir
LL_FROM_MLIR=/tmp/hello-sasha.ll
BAD_LL=/tmp/bad.ll
cat > "$MLIR" <<'EOF'
module {
llvm.func @helper(%arg0: i32) -> i32 {
llvm.return %arg0 : i32
}
llvm.func @call_op(%arg0: i32) -> i32 {
%0 = llvm.call fastcc tail @helper(%arg0) {fastmathFlags = #llvm.fastmath<nnan, ninf>} : (i32) -> i32
llvm.return %0 : i32
}
}
EOF
echo "(1) mlir-opt (should accept)"
mlir-opt --verify-diagnostics "$MLIR" && echo "-> accepted"
echo
echo "(2) mlir-translate (should silently drop nnan ninf)"
mlir-translate --mlir-to-llvmir "$MLIR" > "$LL_FROM_MLIR"
grep "tail call" "$LL_FROM_MLIR"
echo "-> (no nnan/ninf above = flags silently dropped by LLVM IRBuilder)"
echo
echo "(3) llvm-as on translator output (accepts; flags already gone)"
llvm-as "$LL_FROM_MLIR" -o /dev/null && echo "-> accepted"
echo
echo "(4) llvm-as on hand-written .ll with flags on int call (should reject)"
cat > "$BAD_LL" <<'EOF'
define i32 @helper(i32 %0) {
ret i32 %0
}
define i32 @call_op(i32 %0) {
%2 = tail call nnan ninf fastcc i32 @helper(i32 %0)
ret i32 %2
}
EOF
llvm-as "$BAD_LL" -o /dev/null || echo "-> rejected as expected"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment